Package com.zebra.sdk.remote.comm
Class RemoteStatusConnection
Object
com.zebra.sdk.comm.ConnectionA
com.zebra.sdk.comm.ConnectionStatusA
com.zebra.sdk.remote.comm.RemoteStatusConnection
- All Implemented Interfaces:
Connection,ConnectionWithWriteLogging,StatusConnection,StatusConnectionWithWriteLogging
Establishes a status only Remote connection to a device.
package test.zebra.sdk.comm.examples;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.printer.SGD;
import com.zebra.sdk.remote.comm.RemoteStatusConnection;
public class RemoteStatusConnectionExample {
// This example assumes Link-OS printers are connected via Web Sockets to a server which is running a Zebra servlet
// instance.
public static void main(String[] args) throws Exception {
new RemoteStatusConnectionExample().sendJSONOverStatusChannel("myPrinterUUID");
}
private void sendJSONOverStatusChannel(String theIpAddress) throws ConnectionException {
// Instantiate a remote status connection to the printer specified by UUID using the default Zebra Web
// services port (11995).
// Note: The printer must be connected to a server which is running a Zebra servlet instance.
Connection thePrinterConn = new RemoteStatusConnection(theIpAddress);
try {
// Open the connection - physical connection is established here.
thePrinterConn.open();
// This sends down JSON to the status channel to retrieve the 'appl.name' setting
String firmwareVersion = SGD.GET("appl.name", thePrinterConn);
System.out.println("The firmware version is : " + firmwareVersion);
} catch (ConnectionException e) {
// Handle communications error here.
e.printStackTrace();
} finally {
// Close the connection to release resources.
thePrinterConn.close();
}
}
}
-
Constructor Summary
ConstructorsConstructorDescriptionRemoteStatusConnection(String uniqueId) Initializes a new instance of theRemoteStatusConnectionclass using the default Zebra Web services port (11995).
This constructor will use the default timeouts forConnection.read().RemoteStatusConnection(String uniqueId, int rmiServerPort) Initializes a new instance of theRemoteStatusConnectionclass using the specifiedrmiServerPort.RemoteStatusConnection(String uniqueId, int rmiServerPort, int maxTimeoutForRead, int timeToWaitForMoreData) Initializes a new instance of theRemoteStatusConnectionclass using the specifiedrmiServerPort. -
Method Summary
Modifier and TypeMethodDescriptionintReturns an estimate of the number of bytes that can be read from this connection without blocking.voidclose()Closes this connection and releases any system resources associated with the connection.getConnectionReestablisher(long thresholdTime) Returns aConnectionReestablisherwhich allows for easy recreation of a connection which may have been closed.intReturns the RMI server port.Return the remote connection unique id of the status port as the description.Returns the unique ID of the device.booleanReturns true if the connection is open.voidopen()Opens the connection to a device.byte[]read()Reads all the available data from the connection.byte[]read(int maxBytesToRead) ReadsmaxBytesToReadof the available data from the connection.intreadChar()Reads the next byte of data from the connection, similar to a Java InputStream.toString()See the classes which implement this method for the format of the description string.voidwrite(byte[] data) Writesdata.lengthbytes from the specified byte array to this output stream.voidwrite(byte[] data, int offset, int length) Writeslengthbytes fromdatastarting atoffset.Methods inherited from class com.zebra.sdk.comm.ConnectionA
addWriteLogStream, getManufacturer, getMaxDataToWrite, getMaxTimeoutForRead, getTimeToWaitForMoreData, read, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxDataToWrite, setMaxTimeoutForRead, setReadTimeout, setTimeToWaitForMoreData, waitForData, writeMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.zebra.sdk.comm.Connection
getMaxTimeoutForRead, getTimeToWaitForMoreData, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, writeMethods inherited from interface com.zebra.sdk.comm.StatusConnectionWithWriteLogging
addWriteLogStream
-
Constructor Details
-
RemoteStatusConnection
Initializes a new instance of theRemoteStatusConnectionclass using the default Zebra Web services port (11995).
This constructor will use the default timeouts forConnection.read(). The default timeout is a maximum of 5 seconds for any data to be received. If no more data is available after 1 second the read operation is assumed to be complete.
To specify timeouts other than the defaults, use:
RemoteStatusConnection(String, int, int, int)- Parameters:
uniqueId- the UUID of the device.- See Also:
-
RemoteStatusConnection
Initializes a new instance of theRemoteStatusConnectionclass using the specifiedrmiServerPort. This constructor will use the default timeouts forConnection.read(). The default timeout is a maximum of 5 seconds for any data to be received. If no more data is available after 1 second the read operation is assumed to be complete.
To specify timeouts other than the defaults, use:
RemoteStatusConnection(String, int, int, int)- Parameters:
uniqueId- the UUID of the device.rmiServerPort- the port the RMI server is running on.
-
RemoteStatusConnection
public RemoteStatusConnection(String uniqueId, int rmiServerPort, int maxTimeoutForRead, int timeToWaitForMoreData) Initializes a new instance of theRemoteStatusConnectionclass using the specifiedrmiServerPort. This constructor will use the specified timeouts forConnection.read(). The timeout is a maximum ofmaxTimeoutForReadmilliseconds for any data to be received. If no more data is available aftertimeToWaitForMoreDatamilliseconds the read operation is assumed to be complete.- Parameters:
uniqueId- the UUID of the device.rmiServerPort- the port the RMI server is running on.maxTimeoutForRead- the maximum time, in milliseconds, to wait for any data to be received.timeToWaitForMoreData- the maximum time, in milliseconds, to wait in-between reads after the initial read.
-
-
Method Details
-
open
Description copied from interface:ConnectionOpens the connection to a device. If theopenmethod is called when this connection has already been opened, this call is ignored. When a handle to the connection is no longer needed, you must callConnection.close()to free up system resources.- Specified by:
openin interfaceConnection- Overrides:
openin classConnectionA- Throws:
ConnectionException- if the connection cannot be established.- See Also:
-
close
Description copied from interface:ConnectionCloses this connection and releases any system resources associated with the connection. If the connection is already closed then invoking this method has no effect.- Specified by:
closein interfaceConnection- Overrides:
closein classConnectionA- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
write
Description copied from interface:ConnectionWritesdata.lengthbytes from the specified byte array to this output stream. The connection must be open before this method is called. Ifwriteis called when a connection is closed, aConnectionExceptionis thrown.- Specified by:
writein interfaceConnection- Overrides:
writein classConnectionA- Parameters:
data- the data.- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
write
Description copied from interface:ConnectionWriteslengthbytes fromdatastarting atoffset. The connection must be open before this method is called. Ifwriteis called when a connection is closed, aConnectionExceptionis thrown.- Specified by:
writein interfaceConnection- Overrides:
writein classConnectionA- Parameters:
data- the data.offset- the start offset in thedata.length- number of bytes to write.- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
read
Description copied from interface:ConnectionReads all the available data from the connection. This call is non-blocking.byte[] data = printerConnection.read();
- Specified by:
readin interfaceConnection- Overrides:
readin classConnectionA- Returns:
- the bytes read from the connection.
- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
read
Description copied from class:ConnectionAReadsmaxBytesToReadof the available data from the connection. This call is non-blocking.- Overrides:
readin classConnectionA- Parameters:
maxBytesToRead- number of bytes to read- Returns:
- the bytes read from the connection.
- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
readChar
Description copied from interface:ConnectionReads the next byte of data from the connection, similar to a Java InputStream. The value byte is returned as an int in the range of 0 to 255. If no byte is available on the connection the value -1 is returned.int singleCharacter = printerConnection.readChar();
- Specified by:
readCharin interfaceConnection- Overrides:
readCharin classConnectionA- Returns:
- the next byte from the connection
- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
isConnected
public boolean isConnected()Description copied from interface:ConnectionReturns true if the connection is open.- Specified by:
isConnectedin interfaceConnection- Overrides:
isConnectedin classConnectionA- Returns:
trueif this connection is open.- See Also:
-
bytesAvailable
Description copied from interface:ConnectionReturns an estimate of the number of bytes that can be read from this connection without blocking.- Specified by:
bytesAvailablein interfaceConnection- Overrides:
bytesAvailablein classConnectionA- Returns:
- estimated number of bytes available.
- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
getUniqueId
Returns the unique ID of the device.- Returns:
- the unique ID of the device.
-
getRmiServerPort
public int getRmiServerPort()Returns the RMI server port.- Returns:
- the rmiServerPort
-
toString
Description copied from interface:ConnectionSee the classes which implement this method for the format of the description string.- Specified by:
toStringin interfaceConnection- Overrides:
toStringin classObject- Returns:
- the connection description string.
- See Also:
-
getSimpleConnectionName
Return the remote connection unique id of the status port as the description.- Returns:
- a human-readable description of the connection.
- See Also:
-
getConnectionReestablisher
public ConnectionReestablisher getConnectionReestablisher(long thresholdTime) throws ConnectionException Description copied from interface:ConnectionReturns aConnectionReestablisherwhich allows for easy recreation of a connection which may have been closed.- This call should be made while there is still an active connection to the printer (prior to issuing a command which will make the printer non-responsive).
- Specified by:
getConnectionReestablisherin interfaceConnection- Overrides:
getConnectionReestablisherin classConnectionA- Parameters:
thresholdTime- how long the Connection reestablisher will wait before attempting to reconnection to the printer- Returns:
- ConnectionReestablisher
- Throws:
ConnectionException- if the ConnectionReestablisher could not be created.- See Also:
-