org.jgroups.util.Util.createServerSocket()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(172)

本文整理了Java中org.jgroups.util.Util.createServerSocket()方法的一些代码示例,展示了Util.createServerSocket()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.createServerSocket()方法的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util
方法名:createServerSocket

Util.createServerSocket介绍

[英]Finds first available port starting at start_port and returns server socket
[中]查找从start_端口开始的第一个可用端口,并返回服务器套接字

代码示例

代码示例来源:origin: wildfly/wildfly

public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception {
  local=new InetSocketAddress(local_addr, local_port);
  remote=new InetSocketAddress(remote_addr, remote_port);
  srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort(), local.getPort());
  System.out.println("Listening on " + srv_sock.getLocalSocketAddress());
  acceptor=new Acceptor();
  acceptor.start();
  sock=new Socket();
  //sock.bind(local);
  sock.setSendBufferSize(SOCK_SEND_BUF_SIZE);
  sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE);
  try {
    sock.connect(remote);
    output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream()));
    System.out.println("Connected to " + sock.getRemoteSocketAddress());
  }
  catch(Throwable t) {
    System.out.println("Failed connecting to " + remote + ": will only act as server");
  }
}

代码示例来源:origin: wildfly/wildfly

public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception {
  local=new InetSocketAddress(local_addr, local_port);
  remote=new InetSocketAddress(remote_addr, remote_port);
  destination=new IpAddress(remote.getAddress(), remote.getPort());
  srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort());
  System.out.println("Listening on " + srv_sock.getLocalSocketAddress());
  acceptor=new Acceptor();
  acceptor.start();
  sock=new Socket();
  //sock.bind(local);
  sock.setSendBufferSize(SOCK_SEND_BUF_SIZE);
  sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE);
  try {
    sock.connect(remote);
    output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream()));
    System.out.println("Connected to " + sock.getRemoteSocketAddress());
  }
  catch(Throwable t) {
    System.out.println("Failed connecting to " + remote + ": will only act as server");
  }
}

代码示例来源:origin: wildfly/wildfly

public void init() throws Exception {
  super.init();
  srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "srv-sock", bind_addr, bind_port, bind_port+50);
  acceptor=new Acceptor(bind_addr, bind_port);
}

代码示例来源:origin: wildfly/wildfly

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
}

代码示例来源:origin: wildfly/wildfly

protected StateProviderAcceptor createAcceptor() {
  StateProviderAcceptor retval=new StateProviderAcceptor(thread_pool,
                              Util.createServerSocket(getSocketFactory(),
                                          "jgroups.streaming_state_transfer.srv_sock",
                                          bind_addr, bind_port));
  Thread t=getThreadFactory().newThread(retval, "STATE server socket acceptor");
  t.start();
  return retval;
}

代码示例来源:origin: wildfly/wildfly

public void start() throws Exception {
  super.start();
  srv_sock=Util.createServerSocket(getSocketFactory(), "jgroups.stomp.srv_sock", bind_addr, port, port+50);
  if(log.isDebugEnabled())
    log.debug("server socket listening on " + srv_sock.getLocalSocketAddress());
  if(acceptor == null) {
    acceptor=getThreadFactory().newThread(this, "STOMP acceptor");
    acceptor.setDaemon(true);
    acceptor.start();
  }
  endpoint=endpoint_addr != null? endpoint_addr : getAddress();
}

代码示例来源:origin: wildfly/wildfly

/**
 * Creates an instance of {@link TcpServer} that creates a server socket and listens for connections
 * Needs to be started next.
 * @param thread_factory The thread factory used to create new threads
 * @param socket_factory The socket factory used to create sockets
 * @param bind_addr The local address to bind to. If null, the address will be picked by the OS
 * @param srv_port The local port to bind to. If 0, the port will be picked by the OS.
 * @param end_port If srv_port is taken, the next port is tried, until end_port has been reached, in which case an
 *                 exception will be thrown. If srv_port == end_port, only 1 port will be tried.
 * @param external_addr The external address in case of NAT. Ignored if null.
 * @param external_port The external port on the NA. If 0, srv_port is used.
 * @throws Exception Thrown if the creation failed
 */
public TcpServer(ThreadFactory thread_factory, SocketFactory socket_factory,
         InetAddress bind_addr, int srv_port, int end_port,
         InetAddress external_addr, int external_port) throws Exception {
  this(thread_factory, socket_factory);
  // this.srv_sock=this.socket_factory.createServerSocket("jgroups.tcp.server");
  // this.srv_sock.setReuseAddress(reuse_addr);
  // Util.bind(this.srv_sock, bind_addr, srv_port, end_port);
  this.srv_sock=Util.createServerSocket(this.socket_factory, "jgroups.tcp.server", bind_addr, srv_port, end_port);
  acceptor=factory.newThread(new Acceptor(),"TcpServer.Acceptor[" + srv_sock.getLocalPort() + "]");
  local_addr=localAddress(bind_addr, srv_sock.getLocalPort(), external_addr, external_port);
  addConnectionListener(this);
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception {
  local=new InetSocketAddress(local_addr, local_port);
  remote=new InetSocketAddress(remote_addr, remote_port);
  srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort(), local.getPort());
  System.out.println("Listening on " + srv_sock.getLocalSocketAddress());
  acceptor=new Acceptor();
  acceptor.start();
  sock=new Socket();
  //sock.bind(local);
  sock.setSendBufferSize(SOCK_SEND_BUF_SIZE);
  sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE);
  try {
    sock.connect(remote);
    output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream()));
    System.out.println("Connected to " + sock.getRemoteSocketAddress());
  }
  catch(Throwable t) {
    System.out.println("Failed connecting to " + remote + ": will only act as server");
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception {
  local=new InetSocketAddress(local_addr, local_port);
  remote=new InetSocketAddress(remote_addr, remote_port);
  destination=new IpAddress(remote.getAddress(), remote.getPort());
  srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort());
  System.out.println("Listening on " + srv_sock.getLocalSocketAddress());
  acceptor=new Acceptor();
  acceptor.start();
  sock=new Socket();
  //sock.bind(local);
  sock.setSendBufferSize(SOCK_SEND_BUF_SIZE);
  sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE);
  try {
    sock.connect(remote);
    output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream()));
    System.out.println("Connected to " + sock.getRemoteSocketAddress());
  }
  catch(Throwable t) {
    System.out.println("Failed connecting to " + remote + ": will only act as server");
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public void init() throws Exception {
  super.init();
  srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "srv-sock", bind_addr, bind_port, bind_port+50);
  acceptor=new Acceptor(bind_addr, bind_port);
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

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
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

protected StateProviderAcceptor createAcceptor() {
  StateProviderAcceptor retval=new StateProviderAcceptor(thread_pool,
                              Util.createServerSocket(getSocketFactory(),
                                          "jgroups.streaming_state_transfer.srv_sock",
                                          bind_addr, bind_port));
  Thread t=getThreadFactory().newThread(retval, "STATE server socket acceptor");
  t.start();
  return retval;
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public void start() throws Exception {
  super.start();
  srv_sock=Util.createServerSocket(getSocketFactory(), "jgroups.stomp.srv_sock", bind_addr, port, port+50);
  if(log.isDebugEnabled())
    log.debug("server socket listening on " + srv_sock.getLocalSocketAddress());
  if(acceptor == null) {
    acceptor=getThreadFactory().newThread(this, "STOMP acceptor");
    acceptor.setDaemon(true);
    acceptor.start();
  }
  endpoint=endpoint_addr != null? endpoint_addr : getAddress();
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

/**
 * Creates an instance of {@link TcpServer} that creates a server socket and listens for connections
 * Needs to be started next.
 * @param thread_factory The thread factory used to create new threads
 * @param socket_factory The socket factory used to create sockets
 * @param bind_addr The local address to bind to. If null, the address will be picked by the OS
 * @param srv_port The local port to bind to. If 0, the port will be picked by the OS.
 * @param end_port If srv_port is taken, the next port is tried, until end_port has been reached, in which case an
 *                 exception will be thrown. If srv_port == end_port, only 1 port will be tried.
 * @param external_addr The external address in case of NAT. Ignored if null.
 * @param external_port The external port on the NA. If 0, srv_port is used.
 * @throws Exception Thrown if the creation failed
 */
public TcpServer(ThreadFactory thread_factory, SocketFactory socket_factory,
         InetAddress bind_addr, int srv_port, int end_port,
         InetAddress external_addr, int external_port) throws Exception {
  this(thread_factory, socket_factory);
  // this.srv_sock=this.socket_factory.createServerSocket("jgroups.tcp.server");
  // this.srv_sock.setReuseAddress(reuse_addr);
  // Util.bind(this.srv_sock, bind_addr, srv_port, end_port);
  this.srv_sock=Util.createServerSocket(this.socket_factory, "jgroups.tcp.server", bind_addr, srv_port, end_port);
  acceptor=factory.newThread(new Acceptor(),"TcpServer.Acceptor[" + srv_sock.getLocalPort() + "]");
  local_addr=localAddress(bind_addr, srv_sock.getLocalPort(), external_addr, external_port);
  addConnectionListener(this);
}

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

ServerSocket serverSocket = Util.createServerSocket(bind_addr, bind_port);
spawner = new StateProviderThreadSpawner(setupThreadPool(), serverSocket);
new Thread(Util.getGlobalThreadGroup(), spawner, "StateProviderThreadSpawner").start();

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

Object ret=down_prot.down(evt);
group_name=(String)evt.getArg();
srv_sock=Util.createServerSocket(bind_addr, start_port); // grab a random unused port above 10000
srv_sock_addr=new IpAddress(bind_addr, srv_sock.getLocalPort());
startServerSocket();

相关文章

Util类方法