- create message to stop sender threads when stopping desk share

This commit is contained in:
Richard Alam 2012-01-19 17:40:17 +00:00
parent c8ec2df6a6
commit b2a823ab62
4 changed files with 57 additions and 16 deletions

View File

@ -21,7 +21,7 @@ package org.bigbluebutton.deskshare.client.net;
public interface Message {
public enum MessageType {BLOCK, CURSOR};
public enum MessageType {BLOCK, CURSOR, POISON};
public MessageType getMessageType();
}

View File

@ -116,18 +116,7 @@ public class NetworkSocketStreamSender implements Runnable {
System.out.println("Disconnecting socket stream");
if (!processMessages) return;
try {
ByteArrayOutputStream dataToSend = new ByteArrayOutputStream();
dataToSend.reset();
BlockStreamProtocolEncoder.encodeEndStreamMessage(room, dataToSend, seqNumGenerator.getNext());
sendHeader(BlockStreamProtocolEncoder.encodeHeaderAndLength(dataToSend));
sendToStream(dataToSend);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
processMessages = false;
}
}
private void processNextMessageToSend(Message message) throws IOException {
@ -158,6 +147,21 @@ public class NetworkSocketStreamSender implements Runnable {
} else if (message.getMessageType() == Message.MessageType.CURSOR) {
CursorMessage msg = (CursorMessage)message;
sendCursor(msg.getMouseLocation(), msg.getRoom());
} else if (message.getMessageType() == Message.MessageType.POISON) {
System.out.println("Received poison message.");
try {
ByteArrayOutputStream dataToSend = new ByteArrayOutputStream();
dataToSend.reset();
BlockStreamProtocolEncoder.encodeEndStreamMessage(room, dataToSend, seqNumGenerator.getNext());
sendHeader(BlockStreamProtocolEncoder.encodeHeaderAndLength(dataToSend));
sendToStream(dataToSend);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
processMessages = false;
System.out.println("Disconnected socket stream");
}
}
}

View File

@ -164,6 +164,8 @@ public class NetworkStreamSender implements NextBlockRetriever, NetworkStreamLis
stopped = false;
}
private volatile boolean clearQ = true;
public void stop() throws ConnectionException {
stopped = true;
System.out.println(NAME + "Stopping network sender");
@ -171,11 +173,18 @@ public class NetworkStreamSender implements NextBlockRetriever, NetworkStreamLis
if (tunneling) {
httpSenders[i].disconnect();
} else {
socketSenders[i].disconnect();
}
}
// socketSenders[i].disconnect();
if (clearQ) {
clearQ = false;
blockDataQ.clear();
}
send(new PoisonMessage());
}
}
System.out.println("Shutting down executor");
executor.shutdownNow();
System.out.println("Shutting down executor [DONE]");
httpSenders = null;
socketSenders = null;

View File

@ -0,0 +1,28 @@
/**
*
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
* Copyright (c) 2010 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 2.1 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
**/
package org.bigbluebutton.deskshare.client.net;
public class PoisonMessage implements Message {
@Override
public MessageType getMessageType() {
return MessageType.POISON;
}
}