/** * Dispatches this incoming connection to the appropriate manager, depending on the word that was * read. * * @param word * @param client * @param newThread */ public void dispatch(final String word, final Socket client, boolean newThread) { try { client.setSoTimeout(0); } catch (SocketException se) { IOUtils.close(client); return; } // try to find someone who understands this protocol Delegator delegator = (Delegator) protocols.get(word); // no protocol available to handle this word if (delegator == null) { HTTPStat.UNKNOWN_REQUESTS.incrementStat(); if (LOG.isErrorEnabled()) LOG.error("Unknown protocol: " + word); IOUtils.close(client); } delegator.delegate(word, client, newThread); }
public void delegate(final String word, final Socket sock, boolean newThread) { boolean localHost = NetworkUtils.isLocalHost(sock); boolean drop = false; if (localOnly && !localHost) drop = true; if (!localOnly && localHost && ConnectionSettings.LOCAL_IS_PRIVATE.getValue()) drop = true; if (drop) { IOUtils.close(sock); return; } if (blocking && newThread) { Runnable r = new Runnable() { public void run() { acceptor.acceptConnection(word, sock); } }; ThreadFactory.startThread(r, "IncomingConnection"); } else acceptor.acceptConnection(word, sock); }