Package jmri.server.json
Class JsonNamedBeanSocketService<T extends NamedBean,H extends JsonNamedBeanHttpService<T>>
java.lang.Object
jmri.server.json.JsonSocketService<H>
jmri.server.json.JsonNamedBeanSocketService<T,H>
- Type Parameters:
T
- the NamedBean class supported by this serviceH
- the supporting JsonNamedBeanHttpService class
- Direct Known Subclasses:
JsonBlockSocketService
,JsonIdTagSocketService
,JsonLightSocketService
,JsonMemorySocketService
,JsonOblockSocketService
,JsonReporterSocketService
,JsonRouteSocketService
,JsonSensorSocketService
,JsonSignalMastSocketService
,JsonTurnoutSocketService
public class JsonNamedBeanSocketService<T extends NamedBean,H extends JsonNamedBeanHttpService<T>> extends JsonSocketService<H>
Abstract implementation of JsonSocketService with specific support for
NamedBean
objects. Note that services requiring support for
multiple classes of NamedBean cannot extend this class.-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
JsonNamedBeanSocketService.ManagerListener
protected class
JsonNamedBeanSocketService.NamedBeanListener
-
Field Summary
Fields Modifier and Type Field Description protected HashMap<T,JsonNamedBeanSocketService.NamedBeanListener>
beanListeners
protected JsonNamedBeanSocketService.ManagerListener
managerListener
-
Constructor Summary
Constructors Constructor Description JsonNamedBeanSocketService(JsonConnection connection, H service)
-
Method Summary
Modifier and Type Method Description protected void
addListenerToBean(String name)
protected void
addListenerToBean(T bean)
void
onClose()
Perform any teardown required when closing a connection.void
onList(String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
Handle a request for a list of objects.void
onMessage(String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
Handle an inbound message.protected void
removeListenersFromRemovedBeans()
Methods inherited from class jmri.server.json.JsonSocketService
getConnection, getHttpService, getLocale, getVersion, onList, onMessage, setLocale
-
Field Details
-
beanListeners
protected final HashMap<T extends NamedBean,JsonNamedBeanSocketService.NamedBeanListener> beanListeners -
managerListener
-
-
Constructor Details
-
Method Details
-
onMessage
public void onMessage(String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request) throws IOException, JmriException, JsonExceptionDescription copied from class:JsonSocketService
Handle an inbound message.- Specified by:
onMessage
in classJsonSocketService<H extends JsonNamedBeanHttpService<T>>
- Parameters:
type
- The service type; if the implementing service responds to multiple types, it will need to use this to handle data correctlydata
- JSON data; the contents of this will depend on the implementing servicerequest
- The JSON request- Throws:
IOException
- Thrown if the service cannot send a response; this will cause the JSON Server to close its connection to the client if openJmriException
- Thrown if the request cannot be handled; throwing this will cause the JSON Server to pass a 500 UnsupportedOperation message to the clientJsonException
- Thrown if the service needs to pass an error message back to the client
-
onList
public void onList(String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request) throws IOException, JmriException, JsonExceptionDescription copied from class:JsonSocketService
Handle a request for a list of objects. Note that this should not create listeners for items in the list, but should only create listeners for the object providing the list, if applicable.- Specified by:
onList
in classJsonSocketService<H extends JsonNamedBeanHttpService<T>>
- Parameters:
type
- The service type; if the implementing service responds to multiple types, it will need to use this to handle data correctlydata
- JSON data; the contents of this will depend on the implementing servicerequest
- The JSON request- Throws:
IOException
- Thrown if the service cannot send a response; this will cause the JSON Server to close its connection to the client if openJmriException
- Thrown if the request cannot be handled; throwing this will cause the JSON Server to pass a 500 UnsupportedOperation message to the clientJsonException
- If the service needs to pass an error message back to the client; implementing services may throw a JsonException with code 400 and the localized message "UnlistableService" to indicate thattype
should not be listed
-
onClose
Description copied from class:JsonSocketService
Perform any teardown required when closing a connection.- Specified by:
onClose
in classJsonSocketService<H extends JsonNamedBeanHttpService<T>>
-
addListenerToBean
-
addListenerToBean
-
removeListenersFromRemovedBeans
-