Example #1
1
 public void fireEvent(NCCPConnection.ConnectionEvent e) {
   ConnectionListener l;
   int max = listeners.size();
   for (int i = 0; i < max; ++i) {
     ExpCoordinator.print(
         new String(
             "NCCPConnection.fireEvent ("
                 + toString()
                 + ") event: "
                 + e.getType()
                 + " max:"
                 + max
                 + " i:"
                 + i),
         2);
     l = (ConnectionListener) (listeners.elementAt(i));
     switch (e.getType()) {
       case ConnectionEvent.CONNECTION_FAILED:
         l.connectionFailed(e);
         break;
       case ConnectionEvent.CONNECTION_CLOSED:
         l.connectionClosed(e);
         break;
       case ConnectionEvent.CONNECTION_OPENED:
         ExpCoordinator.printer.print(
             new String("Opened control connection (" + toString() + ")"));
         l.connectionOpened(e);
     }
   }
 }
Example #2
0
 public void setConnected(boolean b, boolean process_pending) {
   if (b && state != ConnectionEvent.CONNECTION_OPENED) {
     if (host.length() > 0)
       ExpCoordinator.print(
           "NCCPConnection open connection to ipaddress " + host + " port " + port);
     state = ConnectionEvent.CONNECTION_OPENED;
     // connected = true;
     fireEvent(new ConnectionEvent(this, state));
     ExpCoordinator.printer.print("NCCPConnection.setConnected " + b + " event fired", 8);
     if (process_pending) {
       int max = pendingMessages.size();
       ExpCoordinator.printer.print(new String("   pendingMessages " + max + " elements"), 8);
       for (int i = 0; i < max; ++i) {
         sendMessage((NCCP.Message) pendingMessages.elementAt(i));
       }
       pendingMessages.removeAllElements();
     }
   } else {
     if (!b
         && (state != ConnectionEvent.CONNECTION_CLOSED
             || state != ConnectionEvent.CONNECTION_FAILED)) {
       if (host.length() > 0)
         ExpCoordinator.print(
             new String(
                 "NCCPConnection.setConnected -- Closed control socket for " + host + "." + port));
       state = ConnectionEvent.CONNECTION_CLOSED;
       fireEvent(new ConnectionEvent(this, state));
     }
   }
 }
Example #3
0
  private boolean connectSPPMon() {
    if (state == ConnectionEvent.CONNECTION_PENDING) {
      ExpCoordinator.print(
          new String("NCCPConnection(" + host + ", " + port + ").connect connection pending"), 0);
      while (state == ConnectionEvent.CONNECTION_PENDING) {
        try {
          Thread.sleep(500);
        } catch (java.lang.InterruptedException e) {
        }
      }
      return (isConnected());
    }

    state = ConnectionEvent.CONNECTION_PENDING;
    if (nonProxy != null) {
      try {
        nonProxy.connect();
      } catch (UnknownHostException e) {
        boolean rtn = informUserError("Don't know about host: " + host + ":" + e.getMessage());
        return rtn;
      } catch (SocketTimeoutException e) {
        boolean rtn = informUserError("Socket time out for " + host + ":" + e.getMessage());
        return rtn;
      } catch (IOException e) {
        boolean rtn = informUserError("Couldnt get I/O for " + host + ":" + e.getMessage());
        return rtn;
      }
    }
    return (isConnected());
  }
Example #4
0
 public void read(ONL.Reader rdr) throws java.io.IOException {
   setHost(new String(rdr.readString()));
   setPort(rdr.readInt());
   short cid = (short) rdr.readShort();
   ExpCoordinator.print(
       new String("NCCPConnection.read host:" + getHost() + " port:" + getPort() + " cid:" + cid),
       5);
   if (proxy != null) proxy.setConnectionID(this, cid);
 }
Example #5
0
    public void print(int dlevel) {
      if (msgtype == NCCP.MessageResponse)
        ExpCoordinator.print(
            new String("NCCPConnection.Message Response size = " + msgsize), dlevel);
      else
        ExpCoordinator.print(
            new String("NCCPConnection.Message type = " + msgtype + " size = " + msgsize), dlevel);
      String tmp_str = "";
      int max = msgsize - 2;
      for (int i = 0; i < max; ++i) {
        for (int j = 0; j < 4; ++j) {
          if (i < max) {
            tmp_str = tmp_str.concat(new String(msgbytes[i] + " "));
            ++i;
          }
        }

        ExpCoordinator.print(new String("     " + tmp_str), dlevel);
        tmp_str = "";
      }
    }
Example #6
0
 public void setConnectionID(short cid) {
   ExpCoordinator.print(
       new String(
           "NCCPConnection.setConnectionID host:"
               + getHost()
               + " port:"
               + getPort()
               + " cid:"
               + cid),
       5);
   if (proxy != null) proxy.setConnectionID(this, cid);
 }
Example #7
0
 public void processMessage(DataInputStream dataIn) throws IOException {
   count = 0;
   int msgsize = dataIn.readInt();
   count = 1;
   int msgtype = 0;
   if (msgsize >= 2) msgtype = dataIn.readUnsignedShort();
   else {
     if (msgsize == 1) dataIn.readByte();
     ExpCoordinator.printer.print(
         new String("ERROR:NCCPConnection.run msgsize(" + msgsize + ") < 2 msgtype = " + msgtype));
     ExpCoordinator.printer.printHistory();
     return;
   }
   count = 2;
   switch (msgtype) {
     case NCCP.MessageResponse:
       ExpCoordinator.print(
           new String(
               "NCCPConnection::run message is  NCCP.MessageResponse " + msgsize + " " + msgtype),
           3);
       MessageRunnable tmp_msg = new MessageRunnable(msgsize, msgtype, dataIn);
       tmp_msg.print(5);
       SwingUtilities.invokeLater(tmp_msg);
       break;
     case NCCP.MessagePeriodic:
       ExpCoordinator.printer.print(
           new String(
               "NCCPConnection::run message is  NCCP.MessagePeriodic " + msgsize + " " + msgtype),
           3);
       processPeriodicMsg(msgsize, msgtype, dataIn);
       break;
     default:
       ExpCoordinator.printer.print(
           new String("NCCPConnection::run message is  Other " + msgsize + " " + msgtype));
       SwingUtilities.invokeLater(new MessageRunnable(msgsize, msgtype, dataIn));
   }
 }