Package jade.imtp.leap

Examples of jade.imtp.leap.ICPException


            updateConnectedState();
        }

        final void checkConnection(Connection c) throws ICPException {
            if (c != myConnection) {
                throw new ICPException("Wrong connection");
            }
        }
View Full Code Here


                    synchronized (this) {
                        if ((!active) || (myConnection == null) || (waitingForFlush && (!flush))) {
                            // If we are waiting for flushed packets and the current packet
                            // is a normal (i.e. non-flushed) one, then throw an exception -->
                            // The packet will be put in the queue of packets to be flushed
                            throw new ICPException("Unreachable");
                        }

                        waitingForFlush = false;
                        connectionRefreshed = false;
                    }

                    try {
                        pkt.setSessionID((byte) inpCnt);
                        if (myLogger.isLoggable(Logger.FINE)) {
                            myLogger.log(Logger.FINE, myID + ": Sending command " + inpCnt + " to FE");
                        }

                        long start = System.currentTimeMillis();
                        myConnection.writePacket(pkt);
                        // Asynch-reply: JICPPacket reply = waitForReply(RESPONSE_TIMEOUT);
                        readStartTime = System.currentTimeMillis();
                        JICPPacket reply = myConnection.readPacket();
                        readStartTime = -1;
                        checkTerminatedInfo(reply);
                        lastReceivedTime = System.currentTimeMillis();
                        long end = lastReceivedTime;
                        System.out.println("INP Session " + inpCnt + ". Dispatching time = " + (end - start));

                        if (myLogger.isLoggable(Logger.FINER)) {
                            myLogger.log(Logger.FINER, myID + ": Received response " + inpCnt + " from FE");
                        }
                        if (reply.getType() == JICPProtocol.ERROR_TYPE) {
                            // Communication OK, but there was a JICP error on the peer
                            throw new ICPException(new String(pkt.getData()));
                        }
                        if (!peerActive) {
                            // This is the response to an exit command --> Suicide, without
                            // killing the above container since it is already dying.
                            NIOBEDispatcher.this.shutdown();
                        }
                        inpCnt = (inpCnt + 1) & 0x0f;
                        return reply;
                    } catch (NullPointerException npe) {
                        // This can happen if a resetConnection() occurs just before
                        // myConnection.writePacket()/readPacket() is called.
                        throw new ICPException("Connection reset.");
                    } catch (IOException ioe) {
                        synchronized (this) {
                            if (myConnection != null && !connectionRefreshed) {
                                // There was an IO exception writing data to the connection
                                // --> reset the connection.
                                myLogger.log(Logger.WARNING, myID + ": IOException IC. " + ioe);
                                resetConnection();
                            }
                        }
                        readStartTime = -1;
                        throw new ICPException("Dispatching error.", ioe);
                    }
                } finally {
                    dispatching = false;
                }
            }
View Full Code Here

            expirationDeadline = System.currentTimeMillis() + maxDisconnectionTime;
        }

        final void checkConnection(Connection c) throws ICPException {
            if (c != myConnection) {
                throw new ICPException("Wrong connection");
            }
        }
View Full Code Here

 
  public void init(JICPMediatorManager mgr, String id, Properties props) throws ICPException {
    // Get the msisdn
    msisdn = props.getProperty("msisdn");
    if (msisdn == null) {
      throw new ICPException("Missing MSISDN");
    }
    // Get the singleton SMSManager
    theSMSManager = SMSManager.getInstance(props);
    if (theSMSManager == null) {
      throw new ICPException("Cannot connect to the SMSManager");
    }
    super.init(mgr, id, props);
  }
View Full Code Here

        }
      };
      t.start();
    }
    catch (IOException ioe) {
      throw new ICPException("I/O error opening server socket on port "+localPort);
    }
  }
View Full Code Here

    try {
      hta = (HTTPSAddress) ta;
    }
    catch (ClassCastException cce) {
      throw new ICPException("The TransportAddress "+ta.toString()+" is not an HTTPS Address");
    }

    return hta.toString();
  }
View Full Code Here

      String nodeName = myID.replace(':', '_');
      props.setProperty(Profile.CONTAINER_NAME, nodeName);

      myContainer = new BackEndContainer(props, this);
      if (!myContainer.connect()) {
        throw new ICPException("BackEnd container failed to join the platform");
      }
      //Possibly the node name was re-assigned by the main
      myID = myContainer.here().getName();
      if (myLogger.isLoggable(Logger.CONFIG)) {
        myLogger.log(Logger.CONFIG, "BackEndContainer " + myID + " successfully joined the platform.");
      }
      return new BackEndSkel(myContainer);
    } catch (ProfileException pe) {
      // should never happen
      pe.printStackTrace();
      throw new ICPException("Error creating profile");
    }
  }
View Full Code Here

  public synchronized byte[] dispatch(byte[] payload, boolean flush) throws ICPException {
    JICPPacket pkt = new JICPPacket(JICPProtocol.COMMAND_TYPE, JICPProtocol.DEFAULT_INFO, payload);
    pkt = myOutgoingsHandler.deliverCommand(pkt, flush);
    if (pkt.getType() == JICPProtocol.ERROR_TYPE) {
      // Communication OK, but there was a JICP error on the peer
      throw new ICPException(new String(pkt.getData()));
    }
    return pkt.getData();
  }
View Full Code Here

    public synchronized JICPPacket deliverCommand(JICPPacket cmd, boolean flush) throws ICPException {
      if (frontEndStatus == REACHABLE) {
        // The following check preserves dispatching order when the
        // front-end has just reconnected but flushing of postponed commands has not started yet
        if (waitingForFlush && !flush) {
          throw new ICPException("Upsetting dispatching order");
        }
        waitingForFlush = false;

        // 1) Schedule the command for delivery
        int sid = outCnt;
        outCnt = (outCnt + 1) & MAX_SID;
        if (myLogger.isLoggable(Logger.FINE)) {
          myLogger.log(Logger.FINE, "Scheduling outgoing command for delivery " + sid);
        }
        cmd.setSessionID((byte) sid);
        currentCommand = cmd;
        commandReady = true;
        // Notify the thread that dispatched the response to the previous command (see dispatchResponse())
        notifyAll();

        // 2) Wait for the response
        while (!responseReady) {
          try {
            responseWaiter = Thread.currentThread();
            wait(RESPONSE_TIMEOUT * (1 + cmd.getLength() / 4096));
            responseWaiter = null;
            if (!responseReady) {
              if (frontEndStatus == CONNECTING) {
                // The connection was reset
                myLogger.log(Logger.WARNING, "Connection reset while waiting for response " + sid);
              } else {
                if (frontEndStatus != TERMINATED) {
                  // Response Timeout expired
                  myLogger.log(Logger.WARNING, "Response timeout expired " + sid);
                  setUnreachable();
                }
              }
              outCnt--;
              if (outCnt < 0) {
                outCnt = MAX_SID;
              }
              throw new ICPException("Missing response");
            }
          } catch (InterruptedException ie) {
          }
        }
        if (myLogger.isLoggable(Logger.FINE)) {
          myLogger.log(Logger.FINE, "Response to scheduled command received " + currentResponse.getSessionID());
        }
        responseReady = false;
        return currentResponse;
      } else {
        throw new ICPException("Unreachable");
      }
    }
View Full Code Here

    // any postponed command waiting to be flushed.
    if (myDisconnectionManager.isReachable()) {
      // The following check preserves dispatching order when the
      // device has just reconnected but flushing has not started yet
      if (waitingForFlush && !flush) {
        throw new ICPException("Upsetting dispatching order");
      }
      waitingForFlush = false;

      int sid = outCnt;
      outCnt = (outCnt+1) & 0x0f;
      myLogger.log(Logger.FINE, "Issuing outgoing command "+sid);
      try {
        JICPPacket pkt = new JICPPacket(JICPProtocol.COMMAND_TYPE, JICPProtocol.DEFAULT_INFO, payload);
        pkt.setSessionID((byte) sid);
        pkt = deliver(pkt);
        myLogger.log(Logger.FINE, "Response received "+pkt.getSessionID());
        if (pkt.getType() == JICPProtocol.ERROR_TYPE) {
          // Communication OK, but there was a JICP error on the peer
          throw new ICPException(new String(pkt.getData()));
        }
        return pkt.getData();
      }
      catch (IOException ioe) {
        // Can't reach the BackEnd. Assume we are unreachable
        myLogger.log(Logger.WARNING, "IOException on output connection", ioe);
        myDisconnectionManager.setUnreachable(false);
        throw new ICPException("Dispatching error.", ioe);
      }
    }
    else {
      throw new ICPException("Unreachable");
    }
  }
View Full Code Here

TOP

Related Classes of jade.imtp.leap.ICPException

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.