XPRD
- java.lang.Object
-
- com.dashoptimization.XPRD
-
public class XPRD extends java.lang.Object
Main public class for remote Mosel management
-
-
Field Summary
Modifier and Type Field and Description int
fsrvIteration
Number of iterations performed byfindXsrvs
.int
fsrvMaxWait
Maximum amount of time (in milliseconds) the functionfindXsrvs
waits for replies.int
fsrvPort
UDP port number used byfindXsrvs
for its broadcast messages.java.util.Map<java.lang.String,java.lang.String>
rcmdEnv
Environment variables to be defined when starting Mosel via 'rcmd'.
-
Constructor Summary
Constructor and Description XPRD()
Generate an XPRD object for remote Mosel instance management.
-
Method Summary
Modifier and Type Method and Description XPRDMosel
connect(java.lang.String cnstr)
Create a new instance by opening a connection.XPRDMosel
connect(java.lang.String cnstr, XPRDFileManager fmgr)
Create a new instance using a user defined file manager by opening a connection.void
disconnect(XPRDMosel inst)
Disconnect the specified instance.void
dropNextEvent()
Drop the next event in the queue.int
findXsrvs(int group, int maxIps, java.util.Set<java.lang.String> addrs)
Search xprmsrv servers on the local network.XPRDEvent
getNextEvent()
Get the next event in the queue.boolean
isQueueEmpty()
Check whether the event queue is empty.static boolean
setKeepAlive(long maxfail, long interval)
Change the keepalive timer settings.static void
shutdown()
Shut down the dispatcher.static void
start()
Start the dispatcher.void
waitForEvent()
Wait until an event is available.void
waitForEvent(long timeout)
Wait until an event is available with a time limit.
-
-
-
Field Detail
-
fsrvPort
public int fsrvPort
UDP port number used byfindXsrvs
for its broadcast messages. Default value: 2514
-
fsrvIteration
public int fsrvIteration
Number of iterations performed byfindXsrvs
. Default value: 1
-
fsrvMaxWait
public int fsrvMaxWait
Maximum amount of time (in milliseconds) the functionfindXsrvs
waits for replies. Default value: 1000
-
rcmdEnv
public java.util.Map<java.lang.String,java.lang.String> rcmdEnv
Environment variables to be defined when starting Mosel via 'rcmd'. A variable can be removed from the target environment by associating anull
value to this variable. Default value: null
-
-
Method Detail
-
findXsrvs
public int findXsrvs(int group, int maxIps, java.util.Set<java.lang.String> addrs)
Search xprmsrv servers on the local network. This function sends a broadcast message over the local network and waits for replies from running xprmsrv servers. A given server will reply only to selected group numbers: thegroup
argument specifies this property. The IP addresses of the hosts having replied to the request are returned via the last argument of the function in the form of strings. The maximum size of this set is fixed bymaxIps
. Note that the provided set is not cleared: if it already containsmaxIps
elements the routine returns immediately.- Parameters:
-
group
- group number of the request -
maxIps
- maximum number of addresses to collect -
addrs
- set to return addresses as strings - Returns:
-
the size of
addrs
or-1
if the socket cannot be created - See Also:
-
fsrvPort
,fsrvIteration
,fsrvMaxWait
-
start
public static void start()
Start the dispatcher. Each dispatcher started with this method must be terminated by a call toshutdown()
-
shutdown
public static void shutdown()
Shut down the dispatcher. This method must be used in pair withstart()
-
setKeepAlive
public static boolean setKeepAlive(long maxfail, long interval)
Change the keepalive timer settings. The server sends to its client a keepalive message at fixedinterval
. A connection is considered broken if more thanmaxfail
*interval
seconds have elapsed since the last message received. Setting 0 formaxfail
disables this mechanism.- Parameters:
-
maxfail
- number of time intervals before the connection is considered broken (use 0 to disable; default value:2) -
interval
- number of seconds between 2 keepalive messages (default value:60) - Returns:
-
true
if the operation is successful. This function can be used only if no node is connected
-
connect
public XPRDMosel connect(java.lang.String cnstr, XPRDFileManager fmgr) throws java.io.IOException
Create a new instance using a user defined file manager by opening a connection.- Parameters:
-
cnstr
- connection string. An empty string is equivalent to"rcmd:mosel -r"
-
fmgr
- optional file manager (may benull
). - Returns:
- the newly connected instance
- Throws:
-
java.io.IOException
- If the connection fails.
-
connect
public XPRDMosel connect(java.lang.String cnstr) throws java.io.IOException
Create a new instance by opening a connection.- Parameters:
-
cnstr
- connection string. An empty string is equivalent to"rcmd:mosel -r"
- Returns:
- the newly connected instance
- Throws:
-
java.io.IOException
- If the connection fails. - See Also:
-
connect(cnstr,null)
-
disconnect
public void disconnect(XPRDMosel inst)
Disconnect the specified instance.- Parameters:
-
inst
- instance to disconnect - Throws:
-
java.util.NoSuchElementException
- If the instance is not connected through this XPRD
-
isQueueEmpty
public boolean isQueueEmpty()
Check whether the event queue is empty.- Returns:
-
true
if the queue of events is empty
-
getNextEvent
public XPRDEvent getNextEvent()
Get the next event in the queue.- Returns:
-
next available event or
null
if the queue is empty
-
dropNextEvent
public void dropNextEvent()
Drop the next event in the queue. Nothing is done if the queue is empty
-
waitForEvent
public void waitForEvent()
Wait until an event is available.
-
waitForEvent
public void waitForEvent(long timeout)
Wait until an event is available with a time limit.- Parameters:
-
timeout
- time limit in seconds
-
-