Package jade.imtp.leap

Examples of jade.imtp.leap.ICPException


    @return The serialized response
     */
    public synchronized byte[] dispatch(byte[] payload, boolean flush) throws ICPException {
        if (connectionDropped) {
            dispatchWhileDropped();
            throw new ICPException("Connection dropped");
        } else {
            if (outConnection != null) {
                if (waitingForFlush && !flush) {
                    throw new ICPException("Upsetting dispatching order");
                }
                waitingForFlush = false;

                int status = 0;
                if (myLogger.isLoggable(Logger.FINE)) {
                    myLogger.log(Logger.FINE, "Issuing outgoing command " + outCnt);
                }
                JICPPacket pkt = new JICPPacket(JICPProtocol.COMMAND_TYPE, JICPProtocol.DEFAULT_INFO, payload);
                pkt.setSessionID((byte) outCnt);
                try {
                    writePacket(pkt, outConnection);
                    status = 1;
                    pkt = outConnection.readPacket();
                    if (pkt.getSessionID() != outCnt) {
                        pkt = outConnection.readPacket();
                    }
                    status = 2;
                    if (myLogger.isLoggable(Logger.FINER)) {
                        myLogger.log(Logger.FINER, "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()));
                    }
                    if ((pkt.getInfo() & JICPProtocol.RECONNECT_INFO) != 0) {
                        // The BackEnd is considering the input connection no longer valid
                        refreshInp();
                    }
                    outCnt = (outCnt + 1) & 0x0f;
                    return pkt.getData();
                } catch (IOException ioe) {
                    // Can't reach the BackEnd.
                    myLogger.log(Logger.WARNING, "IOException OC[" + status + "]" + ioe);
                    refreshOut();
                    throw new ICPException("Dispatching error.", ioe);
                }
            } else {
                System.out.println("Out Connection null: refreshingOut = " + refreshingOutput);
                throw new ICPException("Unreachable");
            }
        }
    }
View Full Code Here


    try {
      jta = (JICPAddress) ta;
    }
    catch (ClassCastException cce) {
      throw new ICPException("The TransportAddress "+ta.toString()+" is not a JICPAddress");
    }

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

  public TransportAddress stringToAddr(String s) throws ICPException {
    Vector  addressFields = parseURL(s);
    String protocol = (String) addressFields.elementAt(0);

    if (!NAME.equals(protocol)) {
      throw new ICPException("Unexpected protocol \""+protocol+"\" when \""+NAME+"\" was expected.");
    }

    String host = (String) addressFields.elementAt(1);
    String port = (String) addressFields.elementAt(2);
    String file = (String) addressFields.elementAt(3);
View Full Code Here

      props.setProperty(Profile.CONTAINER_NAME, nodeName);

      myContainer = new BackEndContainer(props, this);
      // BOOTSTRAP_AGENTS Gestire nuovo valore di ritorno
      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

        if(myLogger.isLoggable(Logger.FINER))
          myLogger.log(Logger.FINER,myID+" - Response received from FE "+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()));
        }
        if ((pkt.getInfo() & JICPProtocol.TERMINATED_INFO) != 0) {
          // This is the response to an exit command --> Suicide
          shutdown();
        }
        inpCnt = (inpCnt+1) & 0x0f;
        return pkt;
      }
      catch (IOException ioe) {
        // Can't reach the FrontEnd.
        if(myLogger.isLoggable(Logger.WARNING))
          myLogger.log(Logger.WARNING,myID+" - IOException IC["+status+"]"+ioe);

        inpHolder.resetConnection(false);
        throw new ICPException("Dispatching error.", ioe);
      }
    }
    else {
      throw new ICPException("Unreachable");
    }
  }
View Full Code Here

   */
  public synchronized byte[] dispatch(byte[] payload, boolean flush) throws ICPException {
    if (connectionDropped) {
      myLogger.log(Logger.INFO, "Dispatching with connection dropped. Reconnecting...");
      undrop();
      throw new ICPException("Connection dropped");
    }
    else {
      if (myConnection != null) {
        if (waitingForFlush && !flush) {
          throw new ICPException("Upsetting dispatching order");
        }
        waitingForFlush = false;
       
        if (myLogger.isLoggable(Logger.FINE)) {
          myLogger.log(Logger.FINE, "Issuing outgoing command "+outCnt);
        }
        JICPPacket pkt = new JICPPacket(JICPProtocol.COMMAND_TYPE, JICPProtocol.DEFAULT_INFO, payload);
        pkt.setSessionID((byte) outCnt);
        try {
          lastOutgoingResponse = null;
          //System.out.println("Sending command to BE "+pkt.getSessionID());
          writePacket(pkt, myConnection);
          //System.out.println("Waiting for response from BE "+pkt.getSessionID());
          JICPPacket response = waitForResponse(outCnt, RESPONSE_TIMEOUT);
          if (response != null) {
            //System.out.println("Response received from BE "+response.getSessionID());
            if (myLogger.isLoggable(Logger.FINER)) {
              myLogger.log(Logger.FINER, "Response received "+response.getSessionID());
            }
            if (response.getType() == JICPProtocol.ERROR_TYPE) {
              // Communication OK, but there was a JICP error on the peer
              throw new ICPException(new String(response.getData()));
            }
            outCnt = (outCnt+1) & 0x0f;
            return response.getData();
          }
          else {
            myLogger.log(Logger.WARNING, "Response timeout expired "+pkt.getSessionID());
            handleDisconnection();
            throw new ICPException("Response timeout expired");
          }
        }
        catch (IOException ioe) {
          // Can't reach the BackEnd.
          myLogger.log(Logger.WARNING, ioe.toString());
          handleDisconnection();
          throw new ICPException("Dispatching error.", ioe);
        }
      }
      else {
        throw new ICPException("Unreachable");
      }
    }
  }
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();
      myLogger.log(Logger.CONFIG, myID+" - 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

    return response;
  }

  public JICPPacket handleJICPPacket(JICPPacket pkt, InetAddress addr, int port) throws ICPException {
    throw new ICPException("Unexpected call");
  }
View Full Code Here

    if (status == ACTIVE) {
      if (frontEndStatus == CONNECTED) {
        // 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;
 
        // Wait for the connection to deliver outgoing commands to be ready
        Connection c = getOutgoingCommandsConnection();
 
        // Send the command to the front-end
        JICPPacket cmd = new JICPPacket(JICPProtocol.COMMAND_TYPE, JICPProtocol.DEFAULT_INFO, payload);
        int sid = nextOutgoingCommandSid;
        nextOutgoingCommandSid = increment(nextOutgoingCommandSid);
        if (myLogger.isLoggable(Logger.FINE)) {
          myLogger.log(Logger.FINE, myID+" - Delivering outgoing command to front-end. SID = " + sid);
        }
        cmd.setSessionID((byte) sid);
        boolean deliverOK = false;
        try {
          c.writePacket(cmd);
          close(c);
          // Wait for the response
          JICPPacket response = getResponse(RESPONSE_TIMEOUT + RESPONSE_TIMEOUT_INCREMENT * (cmd.getLength() / 1024));
          deliverOK = true;
          if (myLogger.isLoggable(Logger.FINE)) {
            myLogger.log(Logger.FINE, myID+" - Response got. SID = " + sid);
          }
          if (response.getType() == JICPProtocol.ERROR_TYPE) {
            // Communication OK, but there was a JICP error on the peer
            throw new ICPException(new String(response.getData()));
          }
          return response.getData();
        }
        catch (IOException ioe) {
          setFrontEndDisconnected();
          throw new ICPException("Error delivering outgoing command to front-end. ", ioe);
        }
        catch (ICPException icpe) {
          // Note that in this case setFrontEndDisconnected() is already called within getResponse() or getOutgoingCommandsConnection()
          throw icpe;
        }
        finally {
          if (!deliverOK) {
            nextOutgoingCommandSid = decrement(nextOutgoingCommandSid);
          }
        }
      }
      else {
        throw new ICPException("Front-end not connected");
      }
    }
    else {
      throw new ICPException("Not-active");
    }
  }
View Full Code Here

        while (outgoingCommandsConnection == null) {
          outgoingCommandsConnectionLock.wait(OUTGOING_COMMANDS_CONNECTION_TIMEOUT);
          if (outgoingCommandsConnection == null) {
            if (frontEndStatus == TERMINATED) {
              // We terminated in the meanwhile
              throw new ICPException("Terminated");
            }
            else {
              // Timeout expired
              setFrontEndDisconnected();
              throw new ICPException("Response timeout");
            }
          }
        }
        Connection c = outgoingCommandsConnection;
        outgoingCommandsConnection = null;
        return c;
      }
    }
    catch (InterruptedException ie) {
      throw new ICPException("Interrupted while waiting for outgoing-commands-connection");
    }
  }
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.