Package org.metricshub.ipmi.core.api.sol
Class SerialOverLan
java.lang.Object
org.metricshub.ipmi.core.api.sol.SerialOverLan
- All Implemented Interfaces:
Closeable
,AutoCloseable
Entry point for the Serial Over LAN (SOL) communication. Use all SOL operations through this class.
-
Constructor Summary
ConstructorsConstructorDescriptionSerialOverLan
(IpmiConnector connector, String remoteHost, int remotePort, String user, String password, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) Creates connection with IPMI using givenIpmiConnector
, connected to remote machine on given address and port, and opens a newSession
for SOL communication.SerialOverLan
(IpmiConnector connector, String remoteHost, String user, String password, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) Creates connection with IPMI using givenIpmiConnector
, connected to remote machine on given address and default IPMI port, and opens a newSession
for SOL communication.SerialOverLan
(IpmiConnector connector, Session session) Tries to open SOL communication on given existing session. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
invokeOperations
(SolOperation... operations) Invokes given SOL-specific operations on remote serial port.byte[]
Read all available bytes from the port.byte[]
readBytes
(int byteCount) Reads at max given number of bytes from the port.byte[]
readBytes
(int byteCount, int timeout) Reads at max given number of bytes from the port.int[]
Reads all available bytes from the port as integer (in range from 0 to 255) values array.int[]
readIntArray
(int byteCount) Reads at max given number of integer values (in range from 0 to 255) from the port.int[]
readIntArray
(int byteCount, int timeout) Reads at max given number of integer values (in range from 0 to 255) from the port.readString
(int byteCount) readString
(int byteCount, int timeout) readString
(Charset charset) readString
(Charset charset, int byteCount) readString
(Charset charset, int byteCount, int timeout) void
registerEventListener
(SolEventListener listener) Registers newSolEventListener
that will be informed about SOL events fired by remote system.void
unregisterEventListener
(SolEventListener listener) Unregister givenSolEventListener
, preventing it from receiving SOL events from remote server.boolean
writeByte
(byte singleByte) Writes single byte to the port.boolean
writeBytes
(byte[] buffer) Writes bytes array to the port.boolean
writeInt
(int singleInt) Writes single integer (in range from 0 to 255) to the port.boolean
writeIntArray
(int[] buffer) Writes integers (in range from 0 to 255) array to the port.boolean
writeString
(String string) boolean
writeString
(String string, Charset charset)
-
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 givenIpmiConnector
, connected to remote machine on given address and port, and opens a newSession
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 communicationremoteHost
- IP address of the remote serverremotePort
- UDP port number of the remote serveruser
- IPMI user namepassword
- IPMI passwordcipherSuiteSelectionHandler
-CipherSuiteSelectionHandler
that will allow to selectCipherSuite
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 givenIpmiConnector
, connected to remote machine on given address and default IPMI port, and opens a newSession
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 communicationremoteHost
- IP address of the remote serveruser
- IPMI user namepassword
- IPMI passwordcipherSuiteSelectionHandler
-CipherSuiteSelectionHandler
that will allow to selectCipherSuite
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 communicationsession
- 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
WritesString
to port, using platform's defaultCharset
when convertingString
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
WritesString
to port, using givenCharset
when convertingString
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 portcharset
-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
Read all available bytes from the port and converts them toString
using platform's defaultCharset
. Returns immediately, without waiting for data to be available.- Returns:
- all bytes that could be read as
String
.
-
readString
Reads at max given number of bytes from the port, converting them toString
using platform's defaultCharset
. 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
Reads at max given number of bytes from the port, converting them toString
using platform's defaultCharset
. 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
-
readString
-
readString
Reads at max given number of bytes from the port, converting them toString
using givenCharset
. 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 toString
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
Invokes given SOL-specific operations on remote serial port.- Parameters:
operations
- a bunch ofSolOperation
s that should be invoked- Returns:
- true if operations were successfully sent and acknowledged by remote server, false otherwise.
-
registerEventListener
Registers newSolEventListener
that will be informed about SOL events fired by remote system.- Parameters:
listener
- listener to be registered
-
unregisterEventListener
Unregister givenSolEventListener
, preventing it from receiving SOL events from remote server.- Parameters:
listener
- listener to be unregistered
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-