示例#1
0
 /**
  * Sends the IPMI message to the remote host.
  *
  * @param connectionHandle - {@link ConnectionHandle} associated with the remote host.
  * @param request - {@link IpmiCommandCoder} containing the request to be sent
  * @return ID of the message that will be also attached to the response to pair request with
  *     response if queue was not full and message was sent, -1 if sending of the message failed.
  * @throws ConnectionException when connection is in the state that does not allow to perform this
  *     operation.
  * @throws Exception when sending message to the managed system or initializing one of the
  *     cipherSuite's algorithms fails
  */
 public int sendMessage(ConnectionHandle connectionHandle, IpmiCommandCoder request)
     throws Exception {
   int tries = 0;
   int tag = -1;
   while (tries <= retries && tag < 0) {
     try {
       ++tries;
       while (tag < 0) {
         tag =
             connectionManager
                 .getConnection(connectionHandle.getHandle())
                 .sendIpmiCommand(request);
         if (tag < 0) {
           Thread.sleep(10); // tag < 0 means that MessageQueue is
           // full so we need to wait and retry
         }
       }
       logger.debug("Sending message with tag " + tag + ", try " + tries);
     } catch (IllegalArgumentException e) {
       throw e;
     } catch (Exception e) {
       logger.warn("Failed to send message, cause:", e);
       if (tries > retries) {
         throw e;
       }
     }
   }
   return tag;
 }
示例#2
0
 /**
  * Closes the session with the remote host if it is currently in open state.
  *
  * @param connectionHandle - {@link ConnectionHandle} associated with the remote host.
  * @throws ConnectionException when connection is in the state that does not allow to perform this
  *     operation.
  * @throws Exception when sending message to the managed system or initializing one of the
  *     cipherSuite's algorithms fails
  */
 public void closeSession(ConnectionHandle connectionHandle) throws Exception {
   if (!connectionManager.getConnection(connectionHandle.getHandle()).isSessionValid()) {
     return;
   }
   int tries = 0;
   boolean succeded = false;
   while (tries <= retries && !succeded) {
     try {
       ++tries;
       connectionManager.getConnection(connectionHandle.getHandle()).closeSession();
       succeded = true;
     } catch (Exception e) {
       logger.warn("Failed to receive answer, cause:", e);
       if (tries > retries) {
         throw e;
       }
     }
   }
   return;
 }
示例#3
0
 /**
  * Changes the timeout value for connection with the given handle.
  *
  * @param handle - {@link ConnectionHandle} associated with the remote host.
  * @param timeout - new timeout value in ms
  */
 public void setTimeout(ConnectionHandle handle, int timeout) {
   connectionManager.getConnection(handle.getHandle()).setTimeout(timeout);
 }
示例#4
0
 /** Closes the connection with the given handle */
 public void closeConnection(ConnectionHandle handle) {
   connectionManager.getConnection(handle.getHandle()).unregisterListener(this);
   connectionManager.closeConnection(handle.getHandle());
 }
示例#5
0
 /**
  * Creates connection to the remote host.
  *
  * @param address - {@link InetAddress} of the remote host
  * @return handle to the connection to the remote host
  * @throws IOException when properties file was not found
  * @throws FileNotFoundException when properties file was not found
  */
 public ConnectionHandle createConnection(InetAddress address)
     throws FileNotFoundException, IOException {
   int handle = connectionManager.createConnection(address);
   connectionManager.getConnection(handle).registerListener(this);
   return new ConnectionHandle(handle);
 }