Package org.jgroups.blocks.BasicConnectionTable

Examples of org.jgroups.blocks.BasicConnectionTable.Connection


        num_conns=ct1.getNumConnections();
        assertEquals(1, num_conns);
        num_conns=ct2.getNumConnections();
        assertEquals(1, num_conns);        
       
        Connection connection = ct1.getConnection(addr2);
        assertFalse("valid connection to peer",connection.isSocketClosed());
        connection = ct2.getConnection(addr1);
        assertFalse("valid connection to peer",connection.isSocketClosed());;     
              
    }
View Full Code Here


            catch(Exception e) {
            }
        }

        // 3. then close the connections
        Connection conn;
        Collection tmp=null;
        synchronized(conns) {
            tmp=new LinkedList(conns.values());
            conns.clear();
        }
        if(tmp != null) {
            for(Iterator it=tmp.iterator(); it.hasNext();) {
                conn=(Connection)it.next();
                conn.destroy();
            }
            tmp.clear();
        }
        local_addr=null;
    }
View Full Code Here

    * connection and put it in conns. When the thread should stop, it is
    * interrupted by the thread creator.
    */
   public void run() {
       Socket     client_sock=null;
       Connection conn=null;
       Address    peer_addr;

       while(srv_sock != null) {
           try {
               conn=null;
               client_sock=srv_sock.accept();
               if(!running) {
                   if(log.isWarnEnabled())
                       log.warn("cannot accept connection from " + client_sock.getRemoteSocketAddress() + " as I'm closed");
                   break;
               }
               if(log.isTraceEnabled())
                   log.trace("accepted connection from " + client_sock.getInetAddress() + ":" + client_sock.getPort());
               try {
                   client_sock.setSendBufferSize(send_buf_size);
               }
               catch(IllegalArgumentException ex) {
                   if(log.isErrorEnabled()) log.error("exception setting send buffer size to " +
                          send_buf_size + " bytes", ex);
               }
               try {
                   client_sock.setReceiveBufferSize(recv_buf_size);
               }
               catch(IllegalArgumentException ex) {
                   if(log.isErrorEnabled()) log.error("exception setting receive buffer size to " +
                          send_buf_size + " bytes", ex);
               }

               client_sock.setKeepAlive(true);
               client_sock.setTcpNoDelay(tcp_nodelay);
               if(linger > 0)
                   client_sock.setSoLinger(true, linger);
               else
                   client_sock.setSoLinger(false, -1);

               // create new thread and add to conn table
               conn=new Connection(client_sock, null); // will call receive(msg)
               // get peer's address
               peer_addr=conn.readPeerAddress(client_sock);

               // client_addr=new IpAddress(client_sock.getInetAddress(), client_port);
               conn.setPeerAddress(peer_addr);

               synchronized(conns) {
                  Connection tmp=(Connection) conns.get(peer_addr);
                  //Vladimir Nov, 5th, 2007
                  //we might have a connection to peer but is that
                  //connection still open?
                  boolean connectionOpen  = tmp != null && !tmp.isSocketClosed();
                  if(connectionOpen) {                      
                      if(peer_addr.compareTo(local_addr) > 0) {
                          if(log.isTraceEnabled())
                              log.trace("peer's address (" + peer_addr + ") is greater than our local address (" +
                                      local_addr + "), replacing our existing connection");
View Full Code Here



   /** Try to obtain correct Connection (or create one if not yet existent) */
   Connection getConnection(Address dest) throws Exception {
       Connection conn=null;
       Socket sock;

       synchronized(conns) {
           conn=(Connection)conns.get(dest);
           if(conn == null) {
               // changed by bela Jan 18 2004: use the bind address for the client sockets as well
               SocketAddress tmpBindAddr=new InetSocketAddress(bind_addr, 0);
               InetAddress tmpDest=((IpAddress)dest).getIpAddress();
               SocketAddress destAddr=new InetSocketAddress(tmpDest, ((IpAddress)dest).getPort());
               sock=new Socket();
               sock.bind(tmpBindAddr);
               sock.setKeepAlive(true);
               sock.setTcpNoDelay(tcp_nodelay);
               if(linger > 0)
                   sock.setSoLinger(true, linger);
               else
                   sock.setSoLinger(false, -1);
               sock.connect(destAddr, sock_conn_timeout);

               try {
                   sock.setSendBufferSize(send_buf_size);
               }
               catch(IllegalArgumentException ex) {
                   if(log.isErrorEnabled()) log.error("exception setting send buffer size to " +
                           send_buf_size + " bytes", ex);
               }
               try {
                   sock.setReceiveBufferSize(recv_buf_size);
               }
               catch(IllegalArgumentException ex) {
                   if(log.isErrorEnabled()) log.error("exception setting receive buffer size to " +
                           send_buf_size + " bytes", ex);
               }
               conn=new Connection(sock, dest);
               conn.sendLocalAddress(local_addr);
               notifyConnectionOpened(dest);
               // conns.put(dest, conn);
               addConnection(dest, conn);
               conn.init();
               if(log.isInfoEnabled()) log.info("created socket to " + dest);
           }
           return conn;
       }
   }
View Full Code Here

TOP

Related Classes of org.jgroups.blocks.BasicConnectionTable.Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.