/** Performs the probe asynchronously. */ private void sendProbe() { final NameServicesChannelMessage message = new NameServicesChannelMessage(); message.agent = Nodel.getAgent(); List<String> discoveryList = new ArrayList<String>(1); discoveryList.add("*"); List<String> typesList = new ArrayList<String>(2); typesList.add("tcp"); typesList.add("http"); message.discovery = discoveryList; message.types = typesList; _lastProbe.set(System.nanoTime()); // IO is involved so use a thread-pool _threadPool.execute( new Runnable() { @Override public void run() { sendMessage(_sendSocket, s_sendSocketLabel, _groupSocketAddress, message); // check if hard links (direct "multicasting") are enabled for some hosts if (_hardLinksAddresses != null && _hardLinksSocket != null) { for (InetSocketAddress socketAddress : _hardLinksAddresses) { sendMessage(_hardLinksSocket, s_hardLinksSocketlabel, socketAddress, message); } } } }); }
private void enqueueForProcessing(DatagramPacket dp, String label) { // place it in the queue and make it process if necessary synchronized (_incomingQueue) { QueueEntry qe = new QueueEntry(label, dp); _incomingQueue.add(qe); // kick off the other thread to process the queue // (otherwise the thread will already be processing the queue) if (!_isProcessingIncomingQueue) { _isProcessingIncomingQueue = true; _threadPool.execute(_incomingQueueProcessor); } } }
/** Sends a prepared buffer immediately, optionally using a thread-pool */ private void sendBufferNow(final byte[] buffer, final String origData, boolean onThreadPool) { final OutputStream os; synchronized (_lock) { os = _outputStream; } if (os != null) { if (onThreadPool) { _threadPool.execute( new Runnable() { @Override public void run() { _threadStateHandler.handle(); sendBufferNow0(os, buffer, origData); } }); } else { sendBufferNow0(os, buffer, origData); } } }