Class SerialOverLan

java.lang.Object
org.metricshub.ipmi.core.api.sol.SerialOverLan
All Implemented Interfaces:
Closeable, AutoCloseable

public class SerialOverLan extends Object implements Closeable
Entry point for the Serial Over LAN (SOL) communication. Use all SOL operations through this class.
  • Constructor Details

    • SerialOverLan

      public SerialOverLan(IpmiConnector connector, String remoteHost, int remotePort, String user, String password, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) throws SOLException, SessionException
      Creates connection with IPMI using given IpmiConnector, connected to remote machine on given address and port, and opens a new Session for SOL communication. This constructor should be used only when you have no other connection opened on this port.
      Parameters:
      connector - IpmiConnector that will be used for communication
      remoteHost - IP address of the remote server
      remotePort - UDP port number of the remote server
      user - IPMI user name
      password - IPMI password
      cipherSuiteSelectionHandler - CipherSuiteSelectionHandler that will allow to select CipherSuite among available ones.
      Throws:
      SOLException - when any problem occur during establishing session or activating SOL payload.
      SessionException
    • SerialOverLan

      public SerialOverLan(IpmiConnector connector, String remoteHost, String user, String password, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) throws SOLException, SessionException
      Creates connection with IPMI using given IpmiConnector, connected to remote machine on given address and default IPMI port, and opens a new Session for SOL communication. This constructor should be used only when you have no other connection opened on this port.
      Parameters:
      connector - IpmiConnector that will be used for communication
      remoteHost - IP address of the remote server
      user - IPMI user name
      password - IPMI password
      cipherSuiteSelectionHandler - CipherSuiteSelectionHandler that will allow to select CipherSuite among available ones.
      Throws:
      SOLException - when any problem occur during establishing session or activating SOL payload.
      SessionException
    • SerialOverLan

      public SerialOverLan(IpmiConnector connector, Session session) throws SOLException, SessionException
      Tries to open SOL communication on given existing session. When it appears that separate session must be opened to handle SOL messages (for example SOL payload must be activated on separate port), the new connection and session are automatically established.
      Parameters:
      connector - IpmiConnector that will be used for communication
      session - Existing session that should be reused (if possible) for SOL communication.
      Throws:
      SOLException
      SessionException
  • Method Details

    • writeByte

      public boolean writeByte(byte singleByte)
      Writes single byte to the port. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.
      Parameters:
      singleByte - a byte to write
      Returns:
      true if byte was successfully sent and acknowledged by remote server, false otherwise.
    • writeBytes

      public boolean writeBytes(byte[] buffer)
      Writes bytes array to the port. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.
      Parameters:
      buffer - an array of bytes to write
      Returns:
      true if all bytes were successfully sent and acknowledged by remote server, false otherwise.
    • writeInt

      public boolean writeInt(int singleInt)
      Writes single integer (in range from 0 to 255) to the port. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.
      Parameters:
      singleInt - an integer value to write (must be in range from 0 to 255)
      Returns:
      true if integer was successfully sent and acknowledged by remote server, false otherwise.
    • writeIntArray

      public boolean writeIntArray(int[] buffer)
      Writes integers (in range from 0 to 255) array to the port. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.
      Parameters:
      buffer - an array of integer values to write (each must be in range from 0 to 255)
      Returns:
      true if all integers were successfully sent and acknowledged by remote server, false otherwise.
    • writeString

      public boolean writeString(String string)
      Writes String to port, using platform's default Charset when converting String to byte array. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.
      Parameters:
      string - a string to write to the port.
      Returns:
      true if whole string was successfully sent and acknowledged by remote server, false otherwise.
    • writeString

      public boolean writeString(String string, Charset charset)
      Writes String to port, using given Charset when converting String to byte array. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.
      Parameters:
      string - a string to write to port
      charset - Charset that the string is encoded in
      Returns:
      true if whole string was successfully sent and acknowledged by remote server, false otherwise.
    • readBytes

      public byte[] readBytes()
      Read all available bytes from the port. Returns immediately, without waiting for data to be available.
      Returns:
      all bytes that could be read or empty array if no bytes were available.
    • readBytes

      public byte[] readBytes(int byteCount)
      Reads at max given number of bytes from the port. Returns immediately, without waiting for data to be available.
      Parameters:
      byteCount - maximum number of bytes that should be read
      Returns:
      byte array containing bytes that could be read, but no more than given byteCount. Returns empty array if no bytes were available.
    • readBytes

      public byte[] readBytes(int byteCount, int timeout)
      Reads at max given number of bytes from the port. This operation blocks until given number of bytes is available to be read or until given timeout is hit.
      Parameters:
      byteCount - maximum number of bytes that should be read.
      timeout - maximum time in milliseconds that we want to wait for all available bytes
      Returns:
      byte array containing bytes that could be read, but no more than byteCount. When the timeout is hit, returns just bytes that were available or empty array if no bytes were available.
    • readIntArray

      public int[] readIntArray()
      Reads all available bytes from the port as integer (in range from 0 to 255) values array. Returns immediately, without waiting for data to be available.
      Returns:
      all bytes that could be read as int array (each value in range from 0 to 255) or empty array if no data was available.
    • readIntArray

      public int[] readIntArray(int byteCount)
      Reads at max given number of integer values (in range from 0 to 255) from the port. Returns immediately, without waiting for data to be available.
      Parameters:
      byteCount - maximum number of bytes that should be read
      Returns:
      integer array containing integer values that could be read, but no more than given byteCount (each value in range from 0 to 255). Returns empty array if no data was available.
    • readIntArray

      public int[] readIntArray(int byteCount, int timeout)
      Reads at max given number of integer values (in range from 0 to 255) from the port. This operation blocks until given number of bytes is available to be read or until given timeout is hit.
      Parameters:
      byteCount - maximum number of bytes that should be read.
      timeout - maximum time in milliseconds that we want to wait for all available data
      Returns:
      integer array containing integer values that could be read, but no more than byteCount (each value in range from 0 to 255). When the timeout is hit, returns just data that was available or empty array if no data was available.
    • readString

      public String readString()
      Read all available bytes from the port and converts them to String using platform's default Charset. Returns immediately, without waiting for data to be available.
      Returns:
      all bytes that could be read as String.
    • readString

      public String readString(int byteCount)
      Reads at max given number of bytes from the port, converting them to String using platform's default Charset. Returns immediately, without waiting for data to be available.
      Parameters:
      byteCount - maximum number of bytes that should be read
      Returns:
      all bytes that could be read as String, but no more than given byteCount.
    • readString

      public String readString(int byteCount, int timeout)
      Reads at max given number of bytes from the port, converting them to String using platform's default Charset. This operation blocks until given number of bytes is available to be read or until given timeout is hit.
      Parameters:
      byteCount - maximum number of bytes that should be read.
      timeout - maximum time in milliseconds that we want to wait for all available bytes
      Returns:
      all bytes that could be read as String, but no more than given byteCount. When the timeout is hit, returns just bytes that were available.
    • readString

      public String readString(Charset charset)
      Read all available bytes from the port and converts them to String using given Charset. Returns immediately, without waiting for data to be available.
      Parameters:
      charset - Charset that will be used when converting bytes to String
      Returns:
      all bytes that could be read as String.
    • readString

      public String readString(Charset charset, int byteCount)
      Reads at max given number of bytes from the port, converting them to String using given Charset. Returns immediately, without waiting for data to be available.
      Parameters:
      charset - Charset that will be used when converting bytes to String
      byteCount - maximum number of bytes that should be read
      Returns:
      all bytes that could be read as String, but no more than given byteCount.
    • readString

      public String readString(Charset charset, int byteCount, int timeout)
      Reads at max given number of bytes from the port, converting them to String using given Charset. This operation blocks until given number of bytes is available to be read or until given timeout is hit.
      Parameters:
      charset - Charset that will be used when converting bytes to String
      byteCount - maximum number of bytes that should be read.
      timeout - maximum time in milliseconds that we want to wait for all available bytes
      Returns:
      all bytes that could be read as String, but no more than given byteCount. When the timeout is hit, returns just bytes that were available.
    • invokeOperations

      public boolean invokeOperations(SolOperation... operations)
      Invokes given SOL-specific operations on remote serial port.
      Parameters:
      operations - a bunch of SolOperations that should be invoked
      Returns:
      true if operations were successfully sent and acknowledged by remote server, false otherwise.
    • registerEventListener

      public void registerEventListener(SolEventListener listener)
      Registers new SolEventListener that will be informed about SOL events fired by remote system.
      Parameters:
      listener - listener to be registered
    • unregisterEventListener

      public void unregisterEventListener(SolEventListener listener)
      Unregister given SolEventListener, preventing it from receiving SOL events from remote server.
      Parameters:
      listener - listener to be unregistered
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException