public class MultichannelRemoteConnection extends MultichannelConnection
package test.zebra.sdk.comm.examples;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.printer.PrinterStatus;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import com.zebra.sdk.printer.ZebraPrinterLinkOs;
import com.zebra.sdk.remote.comm.MultichannelRemoteConnection;
public class MultichannelRemoteConnectionExample {
// 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 MultichannelRemoteConnectionExample().simpleExample("myPrinterUUID");
new MultichannelRemoteConnectionExample().nonBlockingStatusReporting("myPrinterUUID");
}
private void simpleExample(String theUniqueId) throws ConnectionException {
// Instantiate Multichannel Remote connection for simultaneous printing and status reporting with a given
// unique ID, 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 MultichannelRemoteConnection(theUniqueId);
try {
// Opens the connection - physical connection is established here.
thePrinterConn.open();
// Creates a Link-OS printing with the given connection
ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.getLinkOsPrinter(thePrinterConn);
// This is sent over the printing channel
linkOsPrinter.printConfigurationLabel();
// This is sent over the status channel
PrinterStatus status = linkOsPrinter.getCurrentStatus();
System.out.println("The printer PAUSED state is : " + status.isPaused);
} catch (ConnectionException e) {
// Handle communications error here.
e.printStackTrace();
} finally {
// Close the connection to release resources.
thePrinterConn.close();
}
}
private void nonBlockingStatusReporting(String theUniqueId) throws ConnectionException {
// Instantiate Multichannel Remote connection for simultaneous printing and status reporting with a given
// unique ID, 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 MultichannelRemoteConnection(theUniqueId);
try {
// Opens the connection - physical connection is established here.
thePrinterConn.open();
// Creates a Link-OS printing with the given connection
ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.getLinkOsPrinter(thePrinterConn);
// This is sent over the printing channel and will block the printing channel until the
// label format is completely sent.
String labelFormatStartCommand = "^XA";
linkOsPrinter.sendCommand(labelFormatStartCommand);
String labelBody = "^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS";
linkOsPrinter.sendCommand(labelBody);
// This is sent over the status channel and will return immediately even though the
// printing channel is in use.
// If a RemoteConnection were used instead of a MultichannelRemoteConnection, this would not be possible.
PrinterStatus status = linkOsPrinter.getCurrentStatus();
System.out.println("The printer PAUSED state is : " + status.isPaused);
// Send the end of label command to finish and print the label.
String labelFormatEndCommand = "^XZ";
linkOsPrinter.sendCommand(labelFormatEndCommand);
} catch (ConnectionException e) {
// Handle communications error here.
e.printStackTrace();
} finally {
// Close the connection to release resources.
thePrinterConn.close();
}
}
}
Constructor and Description |
---|
MultichannelRemoteConnection(String uniqueId)
Initializes a new instance of the
MultichannelRemoteConnection class using the default Zebra Web
services port (11995).This constructor will use the default timeouts for Connection.read() . |
MultichannelRemoteConnection(String uniqueId,
int rmiServerPort)
Initializes a new instance of the
MultichannelRemoteConnection class using the specified
rmiServerPort .This constructor will use the default timeouts for Connection.read() . |
MultichannelRemoteConnection(String uniqueId,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Initializes a new instance of the
MultichannelRemoteConnection class using the default Zebra Web
services port (11995).This constructor will use the specified timeouts for Connection.read() for both channels. |
MultichannelRemoteConnection(String uniqueId,
int rmiServerPort,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Initializes a new instance of the
MultichannelRemoteConnection class using the specified
rmiServerPort .This constructor will use the specified timeouts for Connection.read() for both channels. |
MultichannelRemoteConnection(String uniqueId,
int printingChannelMaxTimeoutForRead,
int printingChannelTimeToWaitForMoreData,
int statusChannelMaxTimeoutForRead,
int statusChannelTimeToWaitForMoreData)
Initializes a new instance of the
MultichannelRemoteConnection class using the default Zebra Web
services port (11995).This constructor will use the specified timeouts for Connection.read() for the channels. |
MultichannelRemoteConnection(String uniqueId,
int rmiServerPort,
int printingChannelMaxTimeoutForRead,
int printingChannelTimeToWaitForMoreData,
int statusChannelMaxTimeoutForRead,
int statusChannelTimeToWaitForMoreData)
Initializes a new instance of the
MultichannelRemoteConnection class using the specified
rmiServerPort .This constructor will use the specified timeouts for Connection.read() for the channels. |
Modifier and Type | Method and Description |
---|---|
ConnectionReestablisher |
getConnectionReestablisher(long thresholdTime)
Returns a
ConnectionReestablisher which allows for easy recreation of a connection which may have
been closed. |
String |
getSimpleConnectionName()
Return the remote connection unique id of the printer port as the description.
|
String |
toString()
Returns
REMOTE_MULTI :[uniqueId]:[rmiServerPort].The uniqueId and rmiServerPort are the parameters which were passed into the
constructor. |
addWriteLogStream, bytesAvailable, close, closePrintingChannel, closeStatusChannel, getMaxTimeoutForRead, getPrintingChannel, getStatusChannel, getTimeToWaitForMoreData, isConnected, open, openPrintingChannel, openStatusChannel, read, read, readChar, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, write, write, write
public MultichannelRemoteConnection(String uniqueId)
MultichannelRemoteConnection
class using the default Zebra Web
services port (11995).Connection.read()
. The default timeout is a maximum of
1 seconds for any data to be received. If no more data is available after 1 second the read operation is assumed
to be complete.MultichannelRemoteConnection(String, int, int, int)
uniqueId
- the UUID of the device.public MultichannelRemoteConnection(String uniqueId, int rmiServerPort)
MultichannelRemoteConnection
class using the specified
rmiServerPort
.Connection.read()
. The default timeout is a maximum of
1 seconds for any data to be received. If no more data is available after 1 second the read operation is assumed
to be complete.MultichannelRemoteConnection(String, int, int, int)
uniqueId
- the UUID of the device.rmiServerPort
- the port the RMI server is running on.public MultichannelRemoteConnection(String uniqueId, int maxTimeoutForRead, int timeToWaitForMoreData)
MultichannelRemoteConnection
class using the default Zebra Web
services port (11995).Connection.read()
for both channels. The timeout is
a maximum of maxTimeoutForRead
milliseconds for any data to be received. If no more data is
available after timeToWaitForMoreData
milliseconds the read operation is assumed to be complete. If
you wish to specify different timeouts for each channel, use
MultichannelRemoteConnection(String, int, int, int, int, int)
.uniqueId
- the UUID of the device.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.public MultichannelRemoteConnection(String uniqueId, int rmiServerPort, int maxTimeoutForRead, int timeToWaitForMoreData)
MultichannelRemoteConnection
class using the specified
rmiServerPort
.Connection.read()
for both channels. The timeout is
a maximum of maxTimeoutForRead
milliseconds for any data to be received. If no more data is
available after timeToWaitForMoreData
milliseconds the read operation is assumed to be complete. If
you wish to specify different timeouts for each channel, use
MultichannelRemoteConnection(String, int, int, int, int, int)
.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.public MultichannelRemoteConnection(String uniqueId, int printingChannelMaxTimeoutForRead, int printingChannelTimeToWaitForMoreData, int statusChannelMaxTimeoutForRead, int statusChannelTimeToWaitForMoreData)
MultichannelRemoteConnection
class using the default Zebra Web
services port (11995).Connection.read()
for the channels. The timeout is a
maximum of printingChannelMaxTimeoutForRead/statusChannelMaxTimeoutForRead
milliseconds for any data
to be received on the printing/status channels respectively. If no more data is available after
printingChannelTimeToWaitForMoreData/statusChannelTimeToWaitForMoreData
milliseconds on the
printing/status channels respectively the read operation is assumed to be complete.uniqueId
- the UUID of the device.printingChannelMaxTimeoutForRead
- the maximum time, in milliseconds, to wait for any data to be received on
the printing channel.printingChannelTimeToWaitForMoreData
- the maximum time, in milliseconds, to wait in-between reads after the
initial read on the printing channel.statusChannelMaxTimeoutForRead
- the maximum time, in milliseconds, to wait for any data to be received on
the status channel.statusChannelTimeToWaitForMoreData
- the maximum time, in milliseconds, to wait in-between reads after the
initial read on the status channel.public MultichannelRemoteConnection(String uniqueId, int rmiServerPort, int printingChannelMaxTimeoutForRead, int printingChannelTimeToWaitForMoreData, int statusChannelMaxTimeoutForRead, int statusChannelTimeToWaitForMoreData)
MultichannelRemoteConnection
class using the specified
rmiServerPort
.Connection.read()
for the channels. The timeout is a
maximum of printingChannelMaxTimeoutForRead/statusChannelMaxTimeoutForRead
milliseconds for any data
to be received on the printing/status channels respectively. If no more data is available after
printingChannelTimeToWaitForMoreData/statusChannelTimeToWaitForMoreData
milliseconds on the
printing/status channels respectively the read operation is assumed to be complete.uniqueId
- the UUID of the device.rmiServerPort
- the port the RMI server is running on.printingChannelMaxTimeoutForRead
- the maximum time, in milliseconds, to wait for any data to be received on
the printing channel.printingChannelTimeToWaitForMoreData
- the maximum time, in milliseconds, to wait in-between reads after the
initial read on the printing channel.statusChannelMaxTimeoutForRead
- the maximum time, in milliseconds, to wait for any data to be received on
the status channel.statusChannelTimeToWaitForMoreData
- the maximum time, in milliseconds, to wait in-between reads after the
initial read on the status channel.public ConnectionReestablisher getConnectionReestablisher(long thresholdTime) throws ConnectionException
Connection
ConnectionReestablisher
which allows for easy recreation of a connection which may have
been closed.
getConnectionReestablisher
in interface Connection
getConnectionReestablisher
in class MultichannelConnection
thresholdTime
- how long the Connection reestablisher will wait before attempting to reconnection to the
printerConnectionException
- if the ConnectionReestablisher could not be created.ConnectionA.getConnectionReestablisher(long thresholdTime)
public String toString()
REMOTE_MULTI
:[uniqueId]:[rmiServerPort].uniqueId
and rmiServerPort
are the parameters which were passed into the
constructor.toString
in interface Connection
toString
in class Object
Object.toString()
public String getSimpleConnectionName()
Connection.getSimpleConnectionName()
© 2017 ZIH Corp. All Rights Reserved.