protected static org.jgroups.Address localAddress(InetAddress bind_addr, int local_port, InetAddress external_addr, int external_port) { if(external_addr != null) return new IpAddress(external_addr, external_port > 0? external_port : local_port); return bind_addr != null? new IpAddress(bind_addr, local_port) : new IpAddress(local_port); }
public IpAddress copy() { return new IpAddress(ip_addr, port); }
public IpAddress asIpAddress() { return new IpAddress(ip_addr, port); }
public StateProviderAcceptor(ExecutorService pool, ServerSocket stateServingSocket) { super(); this.pool=pool; this.serverSocket=stateServingSocket; if(external_addr != null) this.address=new IpAddress(external_addr, external_port > 0? external_port : serverSocket.getLocalPort()); else this.address=new IpAddress(bind_addr, serverSocket.getLocalPort()); }
public Address localAddress() { InetSocketAddress local_addr=sock != null? (InetSocketAddress)sock.getLocalSocketAddress() : null; return local_addr != null? new IpAddress(local_addr) : null; }
protected PhysicalAddress getPhysicalAddress() { return new IpAddress((InetSocketAddress)srv_sock.getLocalSocketAddress()); }
public void setInitialHosts(Collection<InetSocketAddress> hosts) { if(hosts == null || hosts.isEmpty()) return; initial_hosts=hosts.stream().map(h -> new IpAddress(h.getAddress(), h.getPort())).collect(Collectors.toList()); }
@Override public Address localAddress() { InetSocketAddress local_addr=null; if(channel != null) { try {local_addr=(InetSocketAddress)channel.getLocalAddress();} catch(IOException e) {} } return local_addr != null? new IpAddress(local_addr) : null; }
protected static List<Address> resolveAEntries(String dnsQuery, String srcPort) { List<Address> addresses = new ArrayList<>(); try { InetAddress[] inetAddresses = InetAddress.getAllByName(dnsQuery); for (InetAddress address : inetAddresses) { addresses.add(new IpAddress(address, Integer.parseInt(srcPort))); } } catch (UnknownHostException ex) { log.trace("failed to resolve query %s, ex: %s", dnsQuery, ex.getMessage()); } return addresses; } }
public void init() throws Exception { super.init(); physical_addr=new IpAddress(InetAddress.getLoopbackAddress(), port++); }
protected PhysicalAddress getPhysicalAddress() { return sock != null ? new IpAddress(bind_addr, sock.getLocalPort()) : null; }
@ManagedOperation public boolean removeInitialHost(String hostname, int port) { InetSocketAddress isa = new InetSocketAddress(hostname, port); stubManager.unregisterStub(new IpAddress(isa.getAddress(), isa.getPort())); return initial_hosts.remove(isa); }
protected IpAddress createLocalAddress() { if(sock == null || sock.isClosed()) return null; if(external_addr != null) { if(external_port > 0) return new IpAddress(external_addr, external_port); return new IpAddress(external_addr, sock.getLocalPort()); } return new IpAddress(sock.getLocalAddress(), sock.getLocalPort()); }
@ManagedOperation public void addInitialHost(String hostname, int port) { //if there is such a stub already, remove and destroy it removeInitialHost(hostname, port); //now re-add it InetSocketAddress isa = new InetSocketAddress(hostname, port); initial_hosts.add(isa); stubManager.createAndRegisterStub(null, new IpAddress(isa.getAddress(), isa.getPort())); stubManager.connectStubs(); // tries to connect all unconnected stubs }
public Connection(Socket sock) throws Exception { this.sock=sock; peer_addr=new IpAddress((InetSocketAddress)sock.getRemoteSocketAddress()); in=new DataInputStream(createBufferedInputStream(sock.getInputStream())); out=new DataOutputStream(createBufferedOutputStream(sock.getOutputStream())); runner=new Runner(new DefaultThreadFactory("tcp", false, true), "conn-" + sock.getLocalPort(), this, null); }
public TcpConnection(Socket s, TcpServer server) throws Exception { this.sock=s; this.server=server; if(s == null) throw new IllegalArgumentException("Invalid parameter s=" + s); setSocketParameters(s); this.out=new DataOutputStream(createBufferedOutputStream(s.getOutputStream())); this.in=new DataInputStream(createBufferedInputStream(s.getInputStream())); this.connected=sock.isConnected(); this.peer_addr=server.usePeerConnections()? readPeerAddress(s) : new IpAddress((InetSocketAddress)s.getRemoteSocketAddress()); last_access=getTimestamp(); // last time a message was sent or received (ns) }
protected void startServerSocket() throws Exception { srv_sock=Util.createServerSocket(getSocketFactory(), "jgroups.fd_sock.srv_sock", bind_addr, start_port, start_port+port_range); // grab a random unused port above 10000 srv_sock_addr=new IpAddress(external_addr != null? external_addr : bind_addr, external_port > 0? external_port : srv_sock.getLocalPort()); if(local_addr != null) cache.add(local_addr, srv_sock_addr); if(srv_sock_handler != null) srv_sock_handler.start(); // won't start if already running }
public NioConnection(SocketChannel channel, NioBaseServer server) throws Exception { this.channel=channel; this.server=server; setSocketParameters(this.channel.socket()); channel.configureBlocking(false); this.connected=channel.isConnected(); send_buf=new Buffers(server.maxSendBuffers() *2); // space for actual bufs and length bufs! this.peer_addr=server.usePeerConnections()? null /* read by first receive() */ : new IpAddress((InetSocketAddress)channel.getRemoteAddress()); last_access=getTimestamp(); // last time a message was sent or received (ns) }
/** * Creates an instance of an {@link NioClient} that acts as a <em>client</em>: no server channel is created and * no acceptor is started to listen for incoming connections. Instead, a channel is created * (bound to bind_addr/bind_port) and connected to server_addr/server_port. This is used to send messages to the * remote server and receive messages from it. Note that there is only a single TCP connection established between * the client and server. * @param bind_addr The address to which the local channel should bind to. Can be null, then the OS picks the address * @param bind_port The local port. Can be 0, then the OS picks the port. * @param server_addr The address of the server to connect to * @param server_port The port of the server to connect to. * @throws Exception If the creation failed */ public NioClient(InetAddress bind_addr, int bind_port, InetAddress server_addr, int server_port) { this(new DefaultThreadFactory("nio", false), new DefaultSocketFactory()); clientBindAddress(bind_addr).clientBindPort(bind_port); this.remote_addr=new IpAddress(server_addr, server_port); }
public void handleConnect() { if (cluster_name == null || local_addr == null) log.error(Util.getMessage("GroupaddrOrLocaladdrIsNullCannotRegisterWithGossipRouterS")); else { InetAddress bind_addr=getTransport().getBindAddress(); log.trace("registering " + local_addr + " under " + cluster_name + " with GossipRouter"); stubManager.destroyStubs(); PhysicalAddress physical_addr = (PhysicalAddress) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr)); stubManager = new RouterStubManager(this, cluster_name, local_addr, NameCache.get(local_addr), physical_addr, reconnect_interval).useNio(this.use_nio); for (InetSocketAddress host : initial_hosts) { RouterStub stub=stubManager.createAndRegisterStub(new IpAddress(bind_addr, 0), new IpAddress(host.getAddress(), host.getPort())); stub.socketConnectionTimeout(sock_conn_timeout); } stubManager.connectStubs(); } }