Beispiel #1
0
 public void start() throws Exception {
   ct = getConnectionTable(reaper_interval, conn_expire_time, bind_addr, start_port);
   ct.addConnectionListener(this);
   ct.setReceiveBufferSize(recv_buf_size);
   ct.setSendBufferSize(send_buf_size);
   local_addr = ct.getLocalAddress();
   if (additional_data != null && local_addr instanceof IpAddress)
     ((IpAddress) local_addr).setAdditionalData(additional_data);
   passUp(new Event(Event.SET_LOCAL_ADDRESS, local_addr));
 }
Beispiel #2
0
  /** Send a message to the address specified in msg.dest */
  private void sendUnicastMessage(Message msg) {
    IpAddress dest;
    Message copy;
    Object hdr;
    Event evt;

    dest = (IpAddress) msg.getDest(); // guaranteed not to be null
    if (!(dest instanceof IpAddress)) {
      Trace.error("TCP.sendUnicastMessage()", "destination address is not of type IpAddress !");
      return;
    }
    setSourceAddress(msg);

    /* Don't send if destination is local address. Instead, switch dst and src and put in up_queue  */
    if (loopback && local_addr != null && dest != null && dest.equals(local_addr)) {
      copy = msg.copy();
      hdr = copy.getHeader(getName());
      if (hdr != null && hdr instanceof TcpHeader) copy.removeHeader(getName());
      copy.setSrc(local_addr);
      copy.setDest(local_addr);

      evt = new Event(Event.MSG, copy);

      /* Because Protocol.up() is never called by this bottommost layer, we call up() directly in the observer.
      This allows e.g. PerfObserver to get the time of reception of a message */
      if (observer != null) observer.up(evt, up_queue.size());

      passUp(evt);
      return;
    }
    if (Trace.trace)
      Trace.info(
          "TCP.sendUnicastMessage()",
          "dest=" + msg.getDest() + ", hdrs:\n" + msg.printObjectHeaders());
    try {
      if (skip_suspected_members) {
        if (suspected_mbrs.contains(dest)) {
          if (Trace.trace)
            Trace.info(
                "TCP.sendUnicastMessage()",
                "will not send unicast message to " + dest + " as it is currently suspected");
          return;
        }
      }
      ct.send(msg);
    } catch (SocketException e) {
      if (members.contains(dest)) {
        if (!suspected_mbrs.contains(dest)) {
          suspected_mbrs.add(dest);
          passUp(new Event(Event.SUSPECT, dest));
        }
      }
    }
  }
Beispiel #3
0
 public void start() throws Exception {
   ct =
       getConnectionTable(
           reaper_interval, conn_expire_time, bind_addr, external_addr, start_port, end_port);
   ct.setUseSendQueues(use_send_queues);
   ct.setSendQueueSize(send_queue_size);
   // ct.addConnectionListener(this);
   ct.setReceiveBufferSize(recv_buf_size);
   ct.setSendBufferSize(send_buf_size);
   ct.setSocketConnectionTimeout(sock_conn_timeout);
   ct.setTcpNodelay(tcp_nodelay);
   ct.setLinger(linger);
   local_addr = ct.getLocalAddress();
   if (additional_data != null && local_addr instanceof IpAddress)
     ((IpAddress) local_addr).setAdditionalData(additional_data);
   super.start();
 }
Beispiel #4
0
 public void stop() {
   ct.stop();
   super.stop();
 }
Beispiel #5
0
 public void retainAll(Collection members) {
   ct.retainAll(members);
 }
Beispiel #6
0
 public void send(Address dest, byte[] data, int offset, int length) throws Exception {
   ct.send(dest, data, offset, length);
 }
Beispiel #7
0
 public String printConnections() {
   return ct.toString();
 }
Beispiel #8
0
 public int getOpenConnections() {
   return ct.getNumConnections();
 }
Beispiel #9
0
 public void stop() {
   ct.stop();
 }