/** * Creates a PeerGroup for the given context and chain. Blocks will be passed to the chain as they are broadcast * and downloaded. This is probably the constructor you want to use. */ public PeerGroup(Context context, @Nullable AbstractBlockChain chain) { this(context, chain, new NioClientManager()); }
/** * <p>Creates a new client to the given server address using the given {@link StreamConnection} to decode the data. * The given connection <b>MUST</b> be unique to this object. This does not block while waiting for the connection to * open, but will call either the {@link StreamConnection#connectionOpened()} or * {@link StreamConnection#connectionClosed()} callback on the created network event processing thread.</p> * * @param connectTimeoutMillis The connect timeout set on the connection (in milliseconds). 0 is interpreted as no * timeout. */ public NioClient(final SocketAddress serverAddress, final StreamConnection parser, final int connectTimeoutMillis) throws IOException { manager.startAsync(); manager.awaitRunning(); handler = new Handler(parser, connectTimeoutMillis); Futures.addCallback(manager.openConnection(serverAddress, handler), new FutureCallback<SocketAddress>() { @Override public void onSuccess(SocketAddress result) { } @Override public void onFailure(Throwable t) { log.error("Connect to {} failed: {}", serverAddress, Throwables.getRootCause(t)); } }); }
@Override public synchronized void connectionClosed() { manager.stopAsync(); if (!closeCalled) { closeCalled = true; upstreamConnection.connectionClosed(); } }
NioClientManager clientManager = new NioClientManager(); for (final InetAddress addr : addrs) { InetSocketAddress address = new InetSocketAddress(addr, params.getPort()); clientManager.openConnection(address, peer); futures.add(future);
@Override public ListenableFuture<SocketAddress> openConnection(SocketAddress serverAddress, StreamConnection connection) { if (!isRunning()) throw new IllegalStateException(); // Create a new connection, give it a connection as an attachment try { SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); sc.connect(serverAddress); PendingConnect data = new PendingConnect(sc, connection, serverAddress); newConnectionChannels.offer(data); selector.wakeup(); return data.future; } catch (Throwable e) { return Futures.immediateFailedFuture(e); } }
@Override public ListenableFuture<SocketAddress> openConnection(SocketAddress serverAddress, StreamConnection connection) { if (!isRunning()) throw new IllegalStateException(); // Create a new connection, give it a connection as an attachment try { SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); sc.connect(serverAddress); PendingConnect data = new PendingConnect(sc, connection, serverAddress); newConnectionChannels.offer(data); selector.wakeup(); return data.future; } catch (Throwable e) { return Futures.immediateFailedFuture(e); } }
/** * <p>Creates a new client to the given server address using the given {@link StreamConnection} to decode the data. * The given connection <b>MUST</b> be unique to this object. This does not block while waiting for the connection to * open, but will call either the {@link StreamConnection#connectionOpened()} or * {@link StreamConnection#connectionClosed()} callback on the created network event processing thread.</p> * * @param connectTimeoutMillis The connect timeout set on the connection (in milliseconds). 0 is interpreted as no * timeout. */ public NioClient(final SocketAddress serverAddress, final StreamConnection parser, final int connectTimeoutMillis) throws IOException { manager.startAsync(); manager.awaitRunning(); handler = new Handler(parser, connectTimeoutMillis); Futures.addCallback(manager.openConnection(serverAddress, handler), new FutureCallback<SocketAddress>() { @Override public void onSuccess(SocketAddress result) { } @Override public void onFailure(Throwable t) { log.error("Connect to {} failed: {}", serverAddress, Throwables.getRootCause(t)); } }); }
/** * Creates a PeerGroup for the given context and chain. Blocks will be passed to the chain as they are broadcast * and downloaded. This is probably the constructor you want to use. */ public PeerGroup(Context context, @Nullable AbstractBlockChain chain) { this(context, chain, new NioClientManager()); }
@Override public synchronized void connectionClosed() { manager.stopAsync(); if (!closeCalled) { closeCalled = true; upstreamConnection.connectionClosed(); } }
@Override public ListenableFuture<SocketAddress> openConnection(SocketAddress serverAddress, StreamConnection connection) { if (!isRunning()) throw new IllegalStateException(); // Create a new connection, give it a connection as an attachment try { SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); sc.connect(serverAddress); PendingConnect data = new PendingConnect(sc, connection, serverAddress); newConnectionChannels.offer(data); selector.wakeup(); return data.future; } catch (Throwable e) { return Futures.immediateFailedFuture(e); } }
/** * <p>Creates a new client to the given server address using the given {@link StreamConnection} to decode the data. * The given connection <b>MUST</b> be unique to this object. This does not block while waiting for the connection to * open, but will call either the {@link StreamConnection#connectionOpened()} or * {@link StreamConnection#connectionClosed()} callback on the created network event processing thread.</p> * * @param connectTimeoutMillis The connect timeout set on the connection (in milliseconds). 0 is interpreted as no * timeout. */ public NioClient(final SocketAddress serverAddress, final StreamConnection parser, final int connectTimeoutMillis) throws IOException { manager.startAsync(); manager.awaitRunning(); handler = new Handler(parser, connectTimeoutMillis); Futures.addCallback(manager.openConnection(serverAddress, handler), new FutureCallback<SocketAddress>() { @Override public void onSuccess(SocketAddress result) { } @Override public void onFailure(Throwable t) { log.error("Connect to {} failed: {}", serverAddress, Throwables.getRootCause(t)); } }); }
/** * Creates a PeerGroup for the given context and chain. Blocks will be passed to the chain as they are broadcast * and downloaded. This is probably the constructor you want to use. */ public PeerGroup(Context context, @Nullable AbstractBlockChain chain) { this(context, chain, new NioClientManager()); }
@Override public synchronized void connectionClosed() { manager.stopAsync(); if (!closeCalled) { closeCalled = true; upstreamConnection.connectionClosed(); } }
@Override public ListenableFuture<SocketAddress> openConnection(SocketAddress serverAddress, StreamConnection connection) { if (!isRunning()) throw new IllegalStateException(); // Create a new connection, give it a connection as an attachment try { SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); sc.connect(serverAddress); PendingConnect data = new PendingConnect(sc, connection, serverAddress); newConnectionChannels.offer(data); selector.wakeup(); return data.future; } catch (Throwable e) { return Futures.immediateFailedFuture(e); } }
/** * <p>Creates a new client to the given server address using the given {@link StreamConnection} to decode the data. * The given connection <b>MUST</b> be unique to this object. This does not block while waiting for the connection to * open, but will call either the {@link StreamConnection#connectionOpened()} or * {@link StreamConnection#connectionClosed()} callback on the created network event processing thread.</p> * * @param connectTimeoutMillis The connect timeout set on the connection (in milliseconds). 0 is interpreted as no * timeout. */ public NioClient(final SocketAddress serverAddress, final StreamConnection parser, final int connectTimeoutMillis) throws IOException { manager.startAsync(); manager.awaitRunning(); handler = new Handler(parser, connectTimeoutMillis); Futures.addCallback(manager.openConnection(serverAddress, handler), new FutureCallback<SocketAddress>() { @Override public void onSuccess(SocketAddress result) { } @Override public void onFailure(Throwable t) { log.error("Connect to {} failed: {}", serverAddress, Throwables.getRootCause(t)); } }); }
/** * Creates a PeerGroup for the given context and chain. Blocks will be passed to the chain as they are broadcast * and downloaded. This is probably the constructor you want to use. */ public PeerGroup(Context context, @Nullable AbstractBlockChain chain) { this(context, chain, new NioClientManager()); }