Example #1
0
 public void sendrecv(Request request, Response response, long timeout) throws IOException {
   synchronized (response_map) {
     makeKey(request);
     response.isReceived = false;
     try {
       response_map.put(request, response);
       doSend(request);
       response.expiration = System.currentTimeMillis() + timeout;
       while (!response.isReceived) {
         response_map.wait(timeout);
         timeout = response.expiration - System.currentTimeMillis();
         if (timeout <= 0) {
           throw new TransportException(name + " timedout waiting for response to " + request);
         }
       }
     } catch (IOException ioe) {
       if (log.level > 2) ioe.printStackTrace(log);
       try {
         disconnect(true);
       } catch (IOException ioe2) {
         ioe2.printStackTrace(log);
       }
       throw ioe;
     } catch (InterruptedException ie) {
       throw new TransportException(ie);
     } finally {
       response_map.remove(request);
     }
   }
 }
Example #2
0
 /**
  * Obtient le socket enregistré correspondant à l'addresse IP donnée.
  *
  * @return le socket correspondant à l'IP source donnée s'il a été enregistré null sinon.
  */
 public Socket popSocket(InetAddress addr) {
   String addrname = toId(addr);
   if (acceptedSockets.containsKey(addrname)) {
     Socket sock = acceptedSockets.get(addrname);
     acceptedSockets.remove(addrname);
     return sock;
   }
   return null;
 }
Example #3
0
  void removeUnboundConnections() {
    if (UnboundConnections.size() == 0) {
      return;
    }
    ArrayList<Long> currentUnboundConnections = UnboundConnections;
    // fix concurrent modification exception
    UnboundConnections = new ArrayList<Long>();
    for (long b : currentUnboundConnections) {
      EventableChannel ec = Connections.remove(b);
      if (ec != null) {
        if (ProxyConnections != null) {
          ProxyConnections.remove(b);
        }
        eventCallback(b, EM_CONNECTION_UNBOUND, null);
        ec.close();

        EventableSocketChannel sc = (EventableSocketChannel) ec;
        if (sc != null && sc.isAttached()) DetachedConnections.add(sc);
      }
    }
  }
Example #4
0
  void removeUnboundConnections() {
    ListIterator<Long> iter = UnboundConnections.listIterator(0);
    while (iter.hasNext()) {
      long b = iter.next();

      EventableChannel ec = Connections.remove(b);
      if (ec != null) {
        eventCallback(b, EM_CONNECTION_UNBOUND, null);
        ec.close();

        EventableSocketChannel sc = (EventableSocketChannel) ec;
        if (sc != null && sc.isAttached()) DetachedConnections.add(sc);
      }
    }
    UnboundConnections.clear();
  }
Example #5
0
  void isAcceptable(SelectionKey k) {
    ServerSocketChannel ss = (ServerSocketChannel) k.channel();
    SocketChannel sn;
    long b;

    for (int n = 0; n < 10; n++) {
      try {
        sn = ss.accept();
        if (sn == null) break;
      } catch (IOException e) {
        e.printStackTrace();
        k.cancel();

        ServerSocketChannel server = Acceptors.remove(k.attachment());
        if (server != null)
          try {
            server.close();
          } catch (IOException ex) {
          }
        ;
        break;
      }

      try {
        sn.configureBlocking(false);
      } catch (IOException e) {
        e.printStackTrace();
        continue;
      }

      b = createBinding();
      EventableSocketChannel ec = new EventableSocketChannel(sn, b, mySelector);
      Connections.put(b, ec);
      NewConnections.add(b);

      eventCallback(((Long) k.attachment()).longValue(), EM_CONNECTION_ACCEPTED, null, b);
    }
  }
    public void OnPointDestroy(long nID) {
      println("OnPointDestroy, handId: " + nID);

      // remove list
      if (_pointLists.containsKey(nID)) _pointLists.remove(nID);
    }
Example #7
0
 /**
  * remove ServiceMonitorFilter
  *
  * @param moduleClassID ServiceMonitor's moduleClassID
  */
 public void removeServiceMonitorFilter(ModuleClassID moduleClassID) {
   serviceMonitorFilters.remove(moduleClassID);
 }
Example #8
0
 public void stopProxy(long from) {
   ProxyConnections.remove(from);
 }
Example #9
0
 public void stopTcpServer(long signature) throws IOException {
   ServerSocketChannel server = Acceptors.remove(signature);
   if (server != null) server.close();
   else throw new RuntimeException("failed to close unknown acceptor");
 }