/** Terminates the manager */ public void terminate() { terminateThread = true; while (!terminated) { ThreadHelper.sleep(10); } socketStructureManagement.terminate(); }
/** Reads messages */ public void run() { while (!terminateThread) { for (int i = 0; i < socketStructureManagement.getSocketStructureCount(); i++) { BinaryDeviceHostAddressSocketStructure currentSocketStructure = (BinaryDeviceHostAddressSocketStructure) socketStructureManagement.getSocketStructure(i); BinaryMessageObject message = null; // read search messages do { message = SocketHelper.readBinaryMessage(null, currentSocketStructure.getDiscoverySocket(), 10); if (message != null) { // Portable.println("Discovery: Received multicast discovery message"); binaryDevice.processDiscoveryMessage(message, currentSocketStructure); } } while (message != null); // read search reply messages do { message = SocketHelper.readBinaryMessage( null, currentSocketStructure.getDescriptionSocket(), 10); if (message != null) { Portable.println( "Description: Received description request from " + IPHelper.toString(message.getSourceAddress()) + " with " + BinaryUPnPConstants.toDebugString(message.getBody())); binaryDevice.processDescriptionMessage(message, currentSocketStructure); } } while (message != null); do { // read control messages message = SocketHelper.readBinaryMessage(null, currentSocketStructure.getControlSocket(), 10); if (message != null) { binaryDevice.processControlMessage(message, currentSocketStructure); } } while (message != null); } ThreadHelper.sleep(50); } terminated = true; }
/** Reads SSDP messages from the multicast sockets of all registered modules */ public void run() { // System.out.println(" Start ExternalSSDPManagement thread, wait for NOTIFY and M-SEARCH // packets..."); while (!terminateThread) { synchronized (listLock) { for (int i = 0; i < socketList.size(); i++) { IDatagramSocket socket = (IDatagramSocket) socketList.elementAt(i); boolean readUDP = true; while (readUDP) { BinaryMessageObject binaryMessage = SocketHelper.readBinaryMessage(udpPacketManager, socket, 20); if (binaryMessage != null) { // System.out.println("Received message from " + // IPAddress.toString(binaryMessage.getSourceAddress())); HTTPMessageObject httpMessage = new HTTPMessageObject( binaryMessage.getBodyAsString(), binaryMessage.getSourceAddress()); // allow message processing by registered handler ((ISSDPMessageHandler) messageHandlerList.elementAt(i)).processMessage(httpMessage); } else { readUDP = false; } } } } if (udpPacketManager != null) { udpPacketManager.triggerEvents(); } ThreadHelper.sleep(50); } System.out.println(" ExternalSSDPManagement thread was shut down"); // close sockets terminated = true; }
/** Terminates the manager */ public void terminate() { terminateThread = true; while (!terminated) { ThreadHelper.sleep(20); } }