Package connection

Examples of connection.Connection$ConnectionData


  }

  @WebMethod
  public boolean connect(String bankName) {
    // Verify if connection already exists
    Connection currentConnection = null;
    try {
      currentConnection = ConnectionPool.getConnection(bankName);
    } catch (Exception e1) {
      e1.printStackTrace();
    }
    // Test the connection state : if already connected then return true
    if (currentConnection != null && currentConnection.getState() == EnumState.connected) {
      return true;
    }
    else if (currentConnection != null && currentConnection.getState() == EnumState.idle) {
      // if idle then ask for a connection
        ConnectionWS currentConnectionWS = new ConnectionWS();
          OutputConnectionWS outputToSend;
      try {
        outputToSend = currentConnectionWS.messageParser("connect_" + bankName);
      } catch (Exception e) {
        e.printStackTrace();
        return false;
      }
      FPDU fpduToSend = outputToSend.getFpdu();
         
          // Send FPDU to the interserver
      if (!sendFPDU(fpduToSend)) {
        // If sendFPDU fail then return false
        return false;
      }
     
    }
   
    // Get the connection and wait for connected state   
    try {
      currentConnection = ConnectionPool.getConnection(bankName);
    } catch (Exception e1) {
      return false;
    }   
    // If null connection return false
    if (currentConnection == null) {
      return false;
    }
    // Wait for connected state
    for (int i = 0; i < PesitImpl.timeOut; i++) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      // Check state of currentConnection
      if (currentConnection.getState() == EnumState.connected) {
        return true;
      }
      else if (currentConnection.getState() == EnumState.connection_refused) {
        break;
      }
    }
   
    // If connection is still idle then the CONNECT message was lost
    // Otherwise it means that the connection is in a particular state for a client and then
    //  - if transfer_in_progress return true
    //  - if wait_for_relconf then return false
    //  TODO : more cases
    if (currentConnection.getState()  == EnumState.idle) {
      // Remove connection from connection pool
      ConnectionPool.returnConnection(bankName, currentConnection);
      return false;
    }
    else if (currentConnection.getState()  == EnumState.waitfor_relconf) {
      return false;
    }
   
    return false;
 
View Full Code Here


 

  @WebMethod
  public boolean disconnect(String bankName) {
    // Check for connection state
    Connection currentConnection = null;
    try {
      currentConnection = ConnectionPool.getConnection(bankName);
    } catch (Exception e1) {
      return false;
    }
   
    // If idle then return true
    // If connection busy then return false
    if (currentConnection.getState() == Connection.EnumState.idle) {
      return true;
    }
    else if (currentConnection.getState() == Connection.EnumState.file_opened
        || currentConnection.getState() == Connection.EnumState.file_selected
        || currentConnection.getState() == Connection.EnumState.transfer_inprogress
        || currentConnection.getState() == Connection.EnumState.waitfor_acconnect
        || currentConnection.getState() == Connection.EnumState.waitfor_relconf) {
      return false;
    }
    // test on idle, waitfor_aconnect, transfer_inprogress, transfer_waiting
    ConnectionWS currentConnectionWS = new ConnectionWS();
        OutputConnectionWS outputToSend;
    try {
      outputToSend = currentConnectionWS.messageParser("release_" + bankName);
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("exception 1");
      return false;
    }
   
    FPDU fpduToSend = outputToSend.getFpdu();
       
    // Send FPDU to the interserver
    if (!sendFPDU(fpduToSend)) {
      // If sendFPDU fail then return false
      return false;
    }
         
    for (int i = 0; i < PesitImpl.timeOut; i++) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      // Check state of currentConnection
      if (currentConnection.getState() == EnumState.idle) {
        return true;
      }
    }
   
    // Update connection state from connection pool
View Full Code Here

      // save stuff
      saveEntry();
      //connect
      ConnectionSettings selected = (ConnectionSettings) table.getItem(
          table.getSelectionIndex()).getData();
      new Connection(RoomManager.getMain().getContainer(), SWT.NONE,
          selected);
    }
    else if(!completed)
      new NSAlertBox("Unable to connect", "The selected connection does not have enough information.", SWT.OK).go();
  }
View Full Code Here

    ArrayList<ConnectionSettings> list = Settings.getSettings().getConnSettings();
   
    for(ConnectionSettings cs:list)
    {
      if(cs.isConnectOnStart())
        new Connection(container, SWT.NONE, cs);
    }
    //RoomManager.colorset = new Customs();
  }
View Full Code Here

    Boolean respBool = false;
   
    ArrayList<FPDU> listFpduResponse = null;
    FPDUParameter parameter = null;
    String remoteBank = fpdu.getParameter().getSender();
    Connection connection = ConnectionPool.getConnection(
        remoteBank);
    if (connection == null) {
      System.out.println("TRANSFER WS Error: No connection for " +
          remoteBank);
      // Raise exception
      throw new TransferException("TRANSFER WS Error: "
          + "No connection for " + remoteBank);
    }
    Transfer transfer = connection.getOutTransfer();
    // First we log the received FPDU
    PeSITLog.logRemote(fpdu);
   
    switch (fpdu.getType()) {
      case READ:
View Full Code Here

     */
    public static Transfer getTransfer(String bank)
      throws TransferException, ConnectionException {
      Transfer t = null;
      // Get the connection associated to the bank
      Connection connection = ConnectionPool.getConnection(
        bank);
    if (connection == null) {
      System.out.println("TRANSFERPOOL Error: No connection for " + bank);
      // Raise exception
      throw new TransferException("TRANSFERPOOL Error: "
          + "No connection for " + bank);
    } else if (connection.getState() != EnumState.connected) {
      // No transfer can start if the connection is not in "connected"
      // state
      System.out.println("TRANSFERPOOL Error: " +
          " Connection with "+ bank +" not in \"connected\" state");
      throw new TransferException("TRANSFERPOOL Error: " +
          " Connection with "+ bank +" not in \"connected\" state");
    }
      // Get the transfer which file name equals the fileName parameter
    t = connection.getOutTransfer();
      if ( t != null) {
        return t;
      }
        // Check if a transfer is already created
        if (!inTransfers.isEmpty( )) {
            t = inTransfers.remove(0);
            // Reset of the transfer
            if(!factory.validateTransfer(t)) {
                t = (Transfer) factory.createTransfer();
                // TODO : find a way to reset idTransfer
            }
            connection.setOutTransfer(t);
        } else if (curTransfers < maxTransfers) {
          // Create a new resource if we haven't
          // reached the limit yet   
          curTransfers++;
            t = (Transfer) factory.createTransfer();
            t.setTransferId(curTransfers);
            // Add a new transfer to the transfer's map of the connection
            connection.setOutTransfer(t);
        }
       
        // If no resources are available, return null for the moment
        return t;
    }
View Full Code Here

     * @throws ConnectionException
     */
    public static void returnTransfer(String bank, String fileName,
        Transfer t) throws ConnectionException {
      // Get the connection associated to the bank
      Connection connection = ConnectionPool.getConnection(
        bank);
        if (connection.getOutTransfer() == null)
            throw new IllegalStateException("Returned item not in pool");
        // Recycle transfer
        inTransfers.add(t);
    }
View Full Code Here

TOP

Related Classes of connection.Connection$ConnectionData

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.