public final class PtolemyServer extends java.lang.Object implements IServerManager
PtolemyServer uses mosquitto from http://mosquitto.org/download.
Under Windows, there is a mosquitto binary available for download.
Under Mac OS X:
cd $PTII/vendors wget http://mosquitto.org/files/source/mosquitto-0.10.2.tar.gz tar -zxf mosquitto-0.10.2.tar.gz cd mosquitto-0.10.2
cmake . make sudo make install
This class requires that the mosquitto binary be running. Under Mac OS X:
/usr/local/sbin/mosquitto &
See the tests in $PTII/ptserver/test/junit for simple code that uses this class.
Modifier and Type | Field and Description |
---|---|
static java.util.ResourceBundle |
CONFIG
The ResourceBundle containing configuration parameters.
|
static int |
IMAGE_BUFFER_SIZE
Buffer size to be used when exporting the model image.
|
static java.lang.String |
IMAGE_FORMAT
Export format of the model image.
|
static java.util.logging.Logger |
LOGGER
The logger that will record Ptolemy errors to the log file.
|
static java.lang.String |
SERVLET_NAME
The virtual path of the command servlet.
|
static java.lang.String |
SERVLET_ROLE
Roles to classify users during basic authentication.
|
Modifier and Type | Method and Description |
---|---|
void |
close(Ticket ticket)
Shut down the simulation thread by calling the finish() method
on its Manager and removing the task from the server.
|
static void |
createInstance(int servletPort,
java.lang.String brokerPath,
java.lang.String brokerAddress,
int brokerPort,
java.lang.String modelDirectory)
Create the singleton with non-default configuration values.
|
byte[] |
downloadModel(java.lang.String url)
Download the selected model to the client.
|
java.lang.String |
getBrokerUrl()
Get the full URL to the message broker.
|
static PtolemyServer |
getInstance()
Get the singleton instance of the Ptolemy server.
|
java.lang.String[] |
getLayoutListing(java.lang.String url)
Get a listing of the layouts for a specific model available on the
server in either the database or the local file system.
|
java.lang.String[] |
getModelListing()
Get a listing of the models available on the server in either the
database or the local file system.
|
java.lang.String |
getServletUrl()
Get the full URL to the servlet application.
|
SimulationTask |
getSimulationTask(Ticket ticket)
Get the simulation task of the provided ticket.
|
Manager.State |
getStateOfSimulation(Ticket ticket)
Get the current state of a specific simulation based on the simulation manager's state.
|
java.util.LinkedHashMap<java.lang.String,java.lang.String> |
getTokenHandlerMap()
Get the token handlers loaded on the server so that they can be
set up on the client.
|
static void |
main(java.lang.String[] args)
Initialize the Ptolemy server, set up the servlet host, and
wait for simulation requests.
|
int |
numberOfSimulations()
Get the number of simulation on the server.
|
ProxyModelResponse |
open(java.lang.String modelUrl,
java.lang.String layoutUrl)
Open a model with the provided model URL and wait for the user to request
the execution of the simulation.
|
void |
pause(Ticket ticket)
Pause the execution of the simulation by calling the pause() method
on its Manager.
|
void |
resume(Ticket ticket)
Resume the execution of the simulation by calling the resume() method
on its Manager.
|
void |
shutdown()
Shut down the broker process and stop all active simulation
threads by calling their Managers.
|
void |
start(Ticket ticket)
Start the execution of the simulation by utilizing a
free thread within the pool.
|
void |
stop(Ticket ticket)
Stop the execution of the simulation by calling the finish() method
on its Manager.
|
public static final java.util.ResourceBundle CONFIG
public static final java.util.logging.Logger LOGGER
public static final java.lang.String IMAGE_FORMAT
public static final int IMAGE_BUFFER_SIZE
public static final java.lang.String SERVLET_NAME
public static final java.lang.String SERVLET_ROLE
public void close(Ticket ticket) throws IllegalActionException
close
in interface IServerManager
ticket
- Ticket reference to the simulation request.IllegalActionException
- If the server was unable to destroy the simulation thread.public static void createInstance(int servletPort, java.lang.String brokerPath, java.lang.String brokerAddress, int brokerPort, java.lang.String modelDirectory) throws IllegalActionException
If any of the parameters are null, then values in the ptserver.PtolemyServerConfig resource are checked. Typically, this file may be found as $PTII/ptserver/PtolemyServerConfig.properties.
servletPort
- The port on which the servlet operates.brokerPath
- The path to the broker executable.brokerAddress
- The host address of the MQTT broker.brokerPort
- The port of the broker.modelDirectory
- The root directory of where model files are stored.
If the value of the modelDirectory is not a directory, then a directory relative
to the value of the ptolemy.ptII.dir (aka $PTII) property is checked.
If that directory does not exist, then $PTII/ptserver/demo is used.IllegalActionException
- If the server could not be created.public byte[] downloadModel(java.lang.String url) throws IllegalActionException
downloadModel
in interface IServerManager
url
- URL of the model file.IllegalActionException
- If the server encountered an
error opening the model file.public java.lang.String getBrokerUrl()
public static PtolemyServer getInstance() throws IllegalActionException
IllegalActionException
- If the server could not be launched.public java.lang.String[] getLayoutListing(java.lang.String url) throws IllegalActionException
getLayoutListing
in interface IServerManager
url
- Address of the model file for which layouts are found.IllegalActionException
- If there was a problem discovering available layouts.public java.lang.String[] getModelListing() throws IllegalActionException
getModelListing
in interface IServerManager
IllegalActionException
- If there was a problem discovering available models.public java.lang.String getServletUrl()
public SimulationTask getSimulationTask(Ticket ticket) throws IllegalActionException
ticket
- The ticket associated with the simulation task.IllegalActionException
- if the ticket is invalid.public Manager.State getStateOfSimulation(Ticket ticket) throws IllegalActionException
ticket
- The ticket reference to the simulation request.IllegalActionException
- If the ticket is invalid or the state
of the running situation could not be determined.public java.util.LinkedHashMap<java.lang.String,java.lang.String> getTokenHandlerMap() throws IllegalActionException
getTokenHandlerMap
in interface IServerManager
IllegalActionException
- If the server was unable to get the handler map.public static void main(java.lang.String[] args) throws IllegalActionException
This class requires that the mosquitto binary be running. See the class comment for information about building, installing and invoking mosquitto.
The following optional command line switches may be used with their accompanying value: -servlet_port, -broker_path (if launching local broker), -broker_address, -broker_port, and -model_dir. The port numbers must be integers, the broker path must be the path to the MQTT broker executable, and the broker address must be the host address. The default values for the command line switches is read from the values in the ptserver.PtolemyServerConfig resource. Typically, this file may be found as $PTII/ptserver/PtolemyServerConfig.properties.
For example:
java -classpath java -classpath $PTII:${PTII}/ptserver/lib/hessian-4.0.7.jar:${PTII}/ptserver/lib/jetty-all-7.4.1.v20110513.jar:${PTII}/ptserver/lib/servlet-api-2.5.jar:${PTII}/ptserver/lib/wmqtt.jar \ ptserver.control.PtolemyServer \ -broker_address 192.168.125.169 -broker_port 1883
args
- Optional command line arguments.IllegalActionException
- If the server could not be launched.public int numberOfSimulations()
public ProxyModelResponse open(java.lang.String modelUrl, java.lang.String layoutUrl) throws IllegalActionException
open
in interface IServerManager
modelUrl
- The path to the model filelayoutUrl
- The path to a model's layout fileIllegalActionException
- If the model fails to load from the provided URL.public void pause(Ticket ticket) throws IllegalActionException
pause
in interface IServerManager
ticket
- The ticket reference to the simulation request.IllegalActionException
- If the server was unable to pause the running simulation.public void resume(Ticket ticket) throws IllegalActionException
resume
in interface IServerManager
ticket
- The ticket reference to the simulation request.IllegalActionException
- If the server was unable to resume the execution of the
simulation.public void shutdown() throws IllegalActionException
IllegalActionException
- If the servlet, broker, or thread pool cannot be stopped.public void start(Ticket ticket) throws IllegalActionException
start
in interface IServerManager
ticket
- The ticket reference to the simulation request.IllegalActionException
- If the server was unable to start the simulation.public void stop(Ticket ticket) throws IllegalActionException
stop
in interface IServerManager
ticket
- The ticket reference to the simulation request.IllegalActionException
- If the server was unable to stop the simulation.