Package jmri.jmris
Class JmriConnection
java.lang.Object
jmri.jmris.JmriConnection
- Direct Known Subclasses:
JsonConnection
Abstraction of DataOutputStream and WebSocket.Connection classes.
Used so that that server objects need only to use a single object/method to send data to any supported object type.
-
Constructor Summary
ConstructorsConstructorDescriptionJmriConnection(DataOutputStream output) Create a JmriConnection that sends output to a DataOutputStream.JmriConnection(org.eclipse.jetty.websocket.api.Session connection) Create a JmriConnection that sends output to a WebSocket. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the connection.org.eclipse.jetty.websocket.api.SessionGet the WebSocket session.voidsendMessage(String message) Send a String to the instantiated connection.void
-
Constructor Details
-
JmriConnection
Create a JmriConnection that sends output to a WebSocket.- Parameters:
connection- WebSocket Session to use.
-
JmriConnection
Create a JmriConnection that sends output to a DataOutputStream.- Parameters:
output- DataOutputStream to use
-
-
Method Details
-
getSession
Get the WebSocket session.- Returns:
- the WebSocket session
-
getDataOutputStream
-
sendMessage
Send a String to the instantiated connection.This method throws an IOException so the server or servlet holding the connection open can respond to the exception if there is an immediate failure. If there is an asynchronous failure, the connection is closed.
- Parameters:
message- message to send- Throws:
IOException- if problem sending message
-
close
Close the connection.Note: Objects using JmriConnection with a
Sessionmay prefer to usegetSession().close()since Session.close() does not throw an IOException.- Throws:
IOException- if problem closing connection
-
getLocale
- Returns:
- the locale
-
setLocale
- Parameters:
locale- the locale to set
-