/** * Allows subclasses of TcpTransportFactory to create custom instances of * TcpTransportServer. * * @param location * @param serverSocketFactory * @return a new TcpTransportServer instance. * @throws IOException * @throws URISyntaxException */ protected TcpTransportServer createTcpTransportServer(final URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException { return new TcpTransportServer(this, location, serverSocketFactory); }
@Override public TransportServer doBind(final URI location) throws IOException { try { Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location)); ServerSocketFactory serverSocketFactory = createServerSocketFactory(); TcpTransportServer server = createTcpTransportServer(location, serverSocketFactory); server.setWireFormatFactory(createWireFormatFactory(options)); IntrospectionSupport.setProperties(server, options); Map<String, Object> transportOptions = IntrospectionSupport.extractProperties(options, "transport."); server.setTransportOption(transportOptions); server.bind(); return server; } catch (URISyntaxException e) { throw IOExceptionSupport.create(e); } }
public void bind() throws IOException { URI bind = getBindLocation(); String host = bind.getHost(); host = (host == null || host.length() == 0) ? "localhost" : host; InetAddress addr = InetAddress.getByName(host); try { serverSocket = serverSocketFactory.createServerSocket(bind.getPort(), backlog, addr); configureServerSocket(serverSocket); } catch (IOException e) { throw IOExceptionSupport.create("Failed to bind to server socket: " + bind + " due to: " + e, e); } try { setConnectURI(new URI(bind.getScheme(), bind.getUserInfo(), resolveHostName(serverSocket, addr), serverSocket.getLocalPort(), bind.getPath(), bind.getQuery(), bind.getFragment())); } catch (URISyntaxException e) { // it could be that the host name contains invalid characters such // as _ on unix platforms so lets try use the IP address instead try { setConnectURI(new URI(bind.getScheme(), bind.getUserInfo(), addr.getHostAddress(), serverSocket.getLocalPort(), bind.getPath(), bind.getQuery(), bind.getFragment())); } catch (URISyntaxException e2) { throw IOExceptionSupport.create(e2); } } }
/** * pull Sockets from the ServerSocket */ @Override public void run() { if (!isStopped() && !isStopping()) { final ServerSocket serverSocket = this.serverSocket; if (serverSocket == null) { onAcceptError(new IOException("Server started without a valid ServerSocket")); } final ServerSocketChannel channel = serverSocket.getChannel(); if (channel != null) { doRunWithServerSocketChannel(channel); } else { doRunWithServerSocket(serverSocket); } } }
private void doRunWithServerSocket(final ServerSocket serverSocket) { while (!isStopped()) { Socket socket = null; try { socket = serverSocket.accept(); if (socket != null) { if (isStopped() || getAcceptListener() == null) { socket.close(); } else { if (useQueueForAccept) { socketQueue.put(socket); } else { handleSocket(socket); } } } } catch (SocketTimeoutException ste) { // expect this to happen } catch (Exception e) { if (!isStopping()) { onAcceptError(e); } else if (!isStopped()) { LOG.warn("run()", e); onAcceptError(e); } } } }
@Override public void run() { try { while (!isStopped() && !isStopping()) { Socket sock = socketQueue.poll(1, TimeUnit.SECONDS); if (sock != null) { try { handleSocket(sock); } catch (Throwable thrown) { if (!isStopping()) { onAcceptError(new Exception(thrown)); } else if (!isStopped()) { LOG.warn("Unexpected error thrown during accept handling: ", thrown); onAcceptError(new Exception(thrown)); } } } } } catch (InterruptedException e) { if (!isStopped() || !isStopping()) { LOG.info("socketQueue interrupted - stopping"); onAcceptError(e); } } } };
options.putAll(transportOptions); TransportInfo transportInfo = configureTransport(this, socket); closeSocket = false; transportInfo.transport, transportInfo.format, options); getAcceptListener().onAccept(configuredTransport); if (!isStopping()) { onAcceptError(e); } else if (!isStopped()) { LOG.warn("run()", e); onAcceptError(e);
Transport transport = createTransport(socket, format); transportFactory.serverConfigure( transport, format, options); getAcceptListener().onAccept(configuredTransport); if (!isStopping()) { onAcceptError(e); } else if (!isStopped()) { LOG.warn("run()", e); onAcceptError(e);
socketHandlerThread = new Thread(null, run, "ActiveMQ Transport Server Thread Handler: " + toString(), getStackSize()); socketHandlerThread.setDaemon(true); socketHandlerThread.setPriority(ThreadPriorities.BROKER_MANAGEMENT - 1);
@Override protected TcpTransportServer createTcpTransportServer(URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException { TcpTransportServer result = new TcpTransportServer(this, location, serverSocketFactory); result.setAllowLinkStealing(true); return result; }
@Override public void setWireFormatFactory(WireFormatFactory factory) { super.setWireFormatFactory(factory); initOpenWireProtocolVerifier(); }
/** * @return pretty print of this */ @Override public String toString() { return "" + getBindLocation(); }
/** * Binds this socket to the previously specified URI. * * Overridden to allow for proper handling of needClientAuth. * * @throws IOException passed up from TcpTransportServer. */ @Override public void bind() throws IOException { super.bind(); if (needClientAuth) { ((SSLServerSocket)this.serverSocket).setNeedClientAuth(true); } else if (wantClientAuth) { ((SSLServerSocket)this.serverSocket).setWantClientAuth(true); } }
protected TransportInfo configureTransport(final TcpTransportServer server, final Socket socket) throws Exception { WireFormat format = wireFormatFactory.createWireFormat(); Transport transport = createTransport(socket, format); return new TransportInfo(format, transport, transportFactory); }
while (!isStopped()) { int count = selector.select(10); SocketChannel sc = channel.accept(); if (sc != null) { if (isStopped() || getAcceptListener() == null) { sc.close(); } else { socketQueue.put(sc.socket()); } else { handleSocket(sc.socket()); if (!isStopping()) { onAcceptError(e); } else if (!isStopped()) { LOG.warn("run()", e); onAcceptError(e); if (!isStopping()) { onAcceptError(ex); } else if (!isStopped()) { LOG.warn("run()", ex); onAcceptError(ex);
options.putAll(transportOptions); TransportInfo transportInfo = configureTransport(this, socket); closeSocket = false; transportInfo.transport, transportInfo.format, options); getAcceptListener().onAccept(configuredTransport); if (!isStopping()) { onAcceptError(e); } else if (!isStopped()) { LOG.warn("run()", e); onAcceptError(e);
/** * pull Sockets from the ServerSocket */ @Override public void run() { if (!isStopped() && !isStopping()) { final ServerSocket serverSocket = this.serverSocket; if (serverSocket == null) { onAcceptError(new IOException("Server started without a valid ServerSocket")); } final ServerSocketChannel channel = serverSocket.getChannel(); if (channel != null) { doRunWithServerSocketChannel(channel); } else { doRunWithServerSocket(serverSocket); } } }
public void run() { try { while (!isStopped() && !isStopping()) { Socket sock = socketQueue.poll(1, TimeUnit.SECONDS); if (sock != null) { handleSocket(sock); } } } catch (InterruptedException e) { LOG.info("socketQueue interuppted - stopping"); if (!isStopping()) { onAcceptError(e); } } }
"ActiveMQ Transport Server Thread Handler: " + toString(), getStackSize()); socketHandlerThread.setDaemon(true); socketHandlerThread.setPriority(ThreadPriorities.BROKER_MANAGEMENT-1);
@Override protected TcpTransportServer createTcpTransportServer(URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException { TcpTransportServer result = new TcpTransportServer(this, location, serverSocketFactory); result.setAllowLinkStealing(true); return result; }