Package omero
Class client
- java.lang.Object
-
- omero.client
-
public class client extends java.lang.ObjectCentral client-side blitz entry point. This class uses solely Ice functionality to provide access to blitz (as opposed to also using Spring) and should be in sync with the OmeroPy omero.client class as well as the OmeroCpp omero::client class. In order to more closely map the destructors in Python and C++, this class keeps a collection ofclientinstances, which are destroyed on program termination. Typical usage:omero.client client = new omero.client(); // Uses ICE_CONFIG omero.client client = new omero.client(host); // Defines "omero.host" omero.client client = new omero.client(host, port); // Defines "omero.host" and "omero.port"For more information, see https://trac.openmicroscopy.org.uk/ome/wiki/ClientDesign- Since:
- 3.0-Beta3
-
-
Constructor Summary
Constructors Constructor Description client()Callsclient(Ice.InitializationData)with a newInitializationDataclient(Ice.InitializationData id)Creates anCommunicatorfrom aInitializationDatainstance.client(java.io.File... files)Creates anCommunicatorfrom multiple files.client(java.lang.String host)Creates anCommunicatorpointing at the given server using theServer.DEFAULT_PORT.client(java.lang.String[] args)Callsclient(String[], Ice.InitializationData)with a newInitializationDataclient(java.lang.String[] args, Ice.InitializationData id)Creates anCommunicatorfrom command-line arguments.client(java.lang.String host, int port)Creates anCommunicatorpointing at the given server with the non-standard port.client(java.util.Map p)Creates anCommunicatorfrom aMapinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void__del__()Calls closeSession() and ignores any exceptions.voidcloseSession()Closes the session and nulls out the communicator.clientcreateClient(boolean secure)Creates a possibly insecureclientinstance and callsjoinSession(String)using the currentsession id.ServiceFactoryPrxcreateSession()CallscreateSession(String, String)with null valuesServiceFactoryPrxcreateSession(java.lang.String username, java.lang.String password)Performs the actual logic of logging in, which is done via thegetRouter(Ice.Communicator).voiddownload(long fileId, java.io.File file)voiddownload(long fileId, java.io.File file, int blockSize)voidenableKeepAlive(int seconds)Resets the "omero.keep_alive" property on the currentCommunicatorwhich is used on initialization to determine the time-period betweenchecks.protected ISessionPrxenv()Helper method to access session environmentprotected static java.lang.StringfilesToString(java.io.File... files)Ice.ObjectAdaptergetAdapter()java.lang.StringgetCategory()Returns the category which should be used for all callbacks passed to the server.Ice.CommunicatorgetCommunicator()Returns theCommunicatorfor this instance or throws an exception if null.intgetDefaultBlockSize()Returns the user-configured setting for "omero.block_size" orDEFAULTBLOCKSIZEif none is set.Ice.ImplicitContextgetImplicitContext()Returns theImplicitContextwhich defines what properties will be sent on every method invocation.RTypegetInput(java.lang.String key)Retrieves an item from the "input" shared (session) memory.java.util.List<java.lang.String>getInputKeys()Returns a list of keys for all items in the "input" shared (session) memoryRTypegetOutput(java.lang.String key)Retrieves an item from the "output" shared (session) memory.java.util.List<java.lang.String>getOutputKeys()Returns a list of keys for all items in the "output" shared (session) memoryIce.PropertiesgetProperties()Returns theactive propertiesfor this instance.java.lang.StringgetProperty(java.lang.String key)Returns the property value for this key or the empty string if none.java.util.Map<java.lang.String,java.lang.String>getPropertyMap()Returns all properties which are prefixed with "omero." or "Ice." using the Properties fromgetProperties().java.util.Map<java.lang.String,java.lang.String>getPropertyMap(Ice.Properties properties)Returns all properties which are prefixed with "omero." or "Ice."static Glacier2.RouterPrxgetRouter(Ice.Communicator comm)Acquires thedefault router, and throws an exception if it is not of type {Glacier2.RouterPrx}.ServiceFactoryPrxgetSession()Returns the current active session or throws an exception if none has beencreatedsince the lastcloseSession()java.lang.StringgetSessionId()Returns the UUID for the current session without making a remote call.java.util.List<StatefulServiceInterfacePrx>getStatefulServices()Returns all activeStatefulServiceInterfaceproxies.booleanisSecure()Specifies whether or not this client was created via a call tocreateClient(boolean)with a boolean of false.ServiceFactoryPrxjoinSession(java.lang.String session)Uses the given session uuid as name and password to rejoin a running session.intkillSession()Calls ISession.closeSession(omero.model.Session) until the returned reference count is greater than zero.voidonHeartbeat(java.lang.Runnable runnable)voidonSessionClosed(java.lang.Runnable runnable)voidonShutdown(java.lang.Runnable runnable)protected java.lang.StringparseAndSetInt(Ice.InitializationData data, java.lang.String key, int newValue)voidsetAgent(java.lang.String agent)Sets theuser agentstring for this client.booleansetFastShutdown(boolean fastShutdown)Sets thefastShutdownflag.voidsetInput(java.lang.String key, RType value)Sets an item in the "input" shared (session) memory under the given name.voidsetIP(java.lang.String ip)Sets theuser ipstring for this client.voidsetOutput(java.lang.String key, RType value)Sets an item in the "output" shared (session) memory under the given name.java.lang.Stringsha1(java.io.File file)Calculates the local sha1 for a file.OriginalFileupload(java.io.File file)OriginalFileupload(java.io.File file, OriginalFile fileObject)OriginalFileupload(java.io.File file, OriginalFile fileObject, java.lang.Integer blockSize)Utility method to upload a file to the server
-
-
-
Constructor Detail
-
client
public client()
Callsclient(Ice.InitializationData)with a newInitializationData
-
client
public client(Ice.InitializationData id)
Creates anCommunicatorfrom aInitializationDatainstance. Cannot be null.- Parameters:
id- the Ice initialization data
-
client
public client(java.lang.String host)
Creates anCommunicatorpointing at the given server using theServer.DEFAULT_PORT.- Parameters:
host- the server host name
-
client
public client(java.lang.String host, int port)Creates anCommunicatorpointing at the given server with the non-standard port.- Parameters:
host- the server host nameport- the server port number
-
client
public client(java.lang.String[] args)
Callsclient(String[], Ice.InitializationData)with a newInitializationData- Parameters:
args- command-line arguments
-
client
public client(java.lang.String[] args, Ice.InitializationData id)Creates anCommunicatorfrom command-line arguments. These are parsed via Ice.Properties.parseIceCommandLineOptions(args) and Ice.Properties.parseCommandLineOptions("omero", args)- Parameters:
args- command-line argumentsid- the Ice initialization data
-
client
public client(java.io.File... files)
Creates anCommunicatorfrom multiple files.- Parameters:
files- files from which to load properties
-
client
public client(java.util.Map p)
Creates anCommunicatorfrom aMapinstance. TheStringrepresentation of each member is added to thePropertiesunder theStringrepresentation of the key.- Parameters:
p- properties
-
-
Method Detail
-
setFastShutdown
public boolean setFastShutdown(boolean fastShutdown)
Sets thefastShutdownflag. By setting this to true, you will prevent proper clean up. This should only be used in the case of network loss (or similar).- Parameters:
fastShutdown- if shutdown should be fast- Returns:
- the previous value of this property
-
setAgent
public void setAgent(java.lang.String agent)
Sets theuser agentstring for this client. Every session creation will be passed this argument. Finding open sessions with the same agent can be done viaISessionPrx.getMyOpenAgentSessions(String).- Parameters:
agent- the user agent for sessions
-
setIP
public void setIP(java.lang.String ip)
Sets theuser ipstring for this client. Every session creation will be passed this argument. Finding open sessions with the same agent can be done viaISessionPrx.getMyOpenAgentSessions(String).- Parameters:
ip- the user IP address
-
isSecure
public boolean isSecure()
Specifies whether or not this client was created via a call tocreateClient(boolean)with a boolean of false. If insecure, then all remote calls will use the insecure connection defined by the server.- Returns:
- if the client's remote calls are secure
-
createClient
public client createClient(boolean secure) throws ServerError, Glacier2.CannotCreateSessionException, Glacier2.PermissionDeniedException
Creates a possibly insecureclientinstance and callsjoinSession(String)using the currentsession id. If secure is false, then first the "omero.router.insecure" configuration property is retrieved from the server and used as the value of "Ice.Default.Router" for the new client. Any exception thrown during creation is passed on to the caller. Note: detachOnDestroy has NOT been called on the session in the returned client. Clients are responsible for doing this immediately if such desired.- Throws:
ServerErrorGlacier2.CannotCreateSessionExceptionGlacier2.PermissionDeniedException
-
__del__
public void __del__()
Calls closeSession() and ignores any exceptions. Equivalent to OmeroPy's __del__ or OmeroCpp's omero::client::~client()
-
getCommunicator
public Ice.Communicator getCommunicator()
Returns theCommunicatorfor this instance or throws an exception if null.- Returns:
- this client's
Communicator
-
getAdapter
public Ice.ObjectAdapter getAdapter()
-
getSession
public ServiceFactoryPrx getSession()
Returns the current active session or throws an exception if none has beencreatedsince the lastcloseSession()- Returns:
- the current active session
-
getSessionId
public java.lang.String getSessionId()
Returns the UUID for the current session without making a remote call. UsesgetSession()internally and will throw an exception if no session is active.- Returns:
- the current session's UUID
-
getCategory
public java.lang.String getCategory()
Returns the category which should be used for all callbacks passed to the server.- Returns:
- the category for callbacks
-
getImplicitContext
public Ice.ImplicitContext getImplicitContext()
Returns theImplicitContextwhich defines what properties will be sent on every method invocation.- Returns:
- the
ImplicitContext
-
getProperties
public Ice.Properties getProperties()
Returns theactive propertiesfor this instance.- Returns:
- the active properties
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Returns the property value for this key or the empty string if none.- Parameters:
key- a property key- Returns:
- the key's value or the empty string if none
-
getPropertyMap
public java.util.Map<java.lang.String,java.lang.String> getPropertyMap()
Returns all properties which are prefixed with "omero." or "Ice." using the Properties fromgetProperties().- Returns:
- the "omero." and "Ice." properties
-
getPropertyMap
public java.util.Map<java.lang.String,java.lang.String> getPropertyMap(Ice.Properties properties)
Returns all properties which are prefixed with "omero." or "Ice."- Parameters:
properties- some Ice properties- Returns:
- the "omero." and "Ice." properties
-
getDefaultBlockSize
public int getDefaultBlockSize()
Returns the user-configured setting for "omero.block_size" orDEFAULTBLOCKSIZEif none is set.- Returns:
- the block size (in bytes)
-
joinSession
public ServiceFactoryPrx joinSession(java.lang.String session) throws Glacier2.CannotCreateSessionException, Glacier2.PermissionDeniedException, ServerError
Uses the given session uuid as name and password to rejoin a running session.- Throws:
Glacier2.CannotCreateSessionExceptionGlacier2.PermissionDeniedExceptionServerError
-
createSession
public ServiceFactoryPrx createSession() throws Glacier2.CannotCreateSessionException, Glacier2.PermissionDeniedException, ServerError
CallscreateSession(String, String)with null values- Throws:
Glacier2.CannotCreateSessionExceptionGlacier2.PermissionDeniedExceptionServerError
-
createSession
public ServiceFactoryPrx createSession(java.lang.String username, java.lang.String password) throws Glacier2.CannotCreateSessionException, Glacier2.PermissionDeniedException, ServerError
Performs the actual logic of logging in, which is done via thegetRouter(Ice.Communicator). Disallows an extantServiceFactoryPrxand tries to re-create a nullCommunicator. A null or empty username will throw an exception, but an empty password is allowed.- Throws:
Glacier2.CannotCreateSessionExceptionGlacier2.PermissionDeniedExceptionServerError
-
getRouter
public static Glacier2.RouterPrx getRouter(Ice.Communicator comm)
Acquires thedefault router, and throws an exception if it is not of type {Glacier2.RouterPrx}. Also sets theImplicitContexton the router proxy.- Parameters:
comm- the Ice communicator- Returns:
- the communicator's router
-
enableKeepAlive
public void enableKeepAlive(int seconds)
Resets the "omero.keep_alive" property on the currentCommunicatorwhich is used on initialization to determine the time-period betweenchecks.
-
getStatefulServices
public java.util.List<StatefulServiceInterfacePrx> getStatefulServices() throws ServerError
Returns all activeStatefulServiceInterfaceproxies. This can be used to call close before calling setSecurityContext.- Throws:
ServerError
-
closeSession
public void closeSession()
Closes the session and nulls out the communicator. This is required by an Ice bug.- See Also:
- 2370 Ice Ping Error
-
killSession
public int killSession()
Calls ISession.closeSession(omero.model.Session) until the returned reference count is greater than zero. The number of invocations is returned. If ISession.closeSession() cannot be called, -1 is returned.
-
sha1
public java.lang.String sha1(java.io.File file)
Calculates the local sha1 for a file.- Parameters:
file- a local file- Returns:
- the file's SHA-1 hexadecimal digest
-
upload
public OriginalFile upload(java.io.File file) throws ServerError, java.io.IOException
- Throws:
ServerErrorjava.io.IOException
-
upload
public OriginalFile upload(java.io.File file, OriginalFile fileObject) throws ServerError, java.io.IOException
- Throws:
ServerErrorjava.io.IOException
-
upload
public OriginalFile upload(java.io.File file, OriginalFile fileObject, java.lang.Integer blockSize) throws ServerError, java.io.IOException
Utility method to upload a file to the server- Parameters:
file- Cannot be null.fileObject- Can be null.blockSize- Can be null.- Throws:
ServerErrorjava.io.IOException
-
download
public void download(long fileId, java.io.File file) throws ServerError, java.io.IOException- Throws:
ServerErrorjava.io.IOException
-
download
public void download(long fileId, java.io.File file, int blockSize) throws ServerError, java.io.IOException- Throws:
ServerErrorjava.io.IOException
-
getInput
public RType getInput(java.lang.String key) throws ServerError
Retrieves an item from the "input" shared (session) memory.- Throws:
ServerError
-
getOutput
public RType getOutput(java.lang.String key) throws ServerError
Retrieves an item from the "output" shared (session) memory.- Throws:
ServerError
-
setInput
public void setInput(java.lang.String key, RType value) throws ServerErrorSets an item in the "input" shared (session) memory under the given name.- Throws:
ServerError
-
setOutput
public void setOutput(java.lang.String key, RType value) throws ServerErrorSets an item in the "output" shared (session) memory under the given name.- Throws:
ServerError
-
getInputKeys
public java.util.List<java.lang.String> getInputKeys() throws ServerErrorReturns a list of keys for all items in the "input" shared (session) memory- Throws:
ServerError
-
getOutputKeys
public java.util.List<java.lang.String> getOutputKeys() throws ServerErrorReturns a list of keys for all items in the "output" shared (session) memory- Throws:
ServerError
-
parseAndSetInt
protected java.lang.String parseAndSetInt(Ice.InitializationData data, java.lang.String key, int newValue)
-
filesToString
protected static java.lang.String filesToString(java.io.File... files)
-
env
protected ISessionPrx env() throws ServerError
Helper method to access session environment- Throws:
ServerError
-
onHeartbeat
public void onHeartbeat(java.lang.Runnable runnable)
-
onSessionClosed
public void onSessionClosed(java.lang.Runnable runnable)
-
onShutdown
public void onShutdown(java.lang.Runnable runnable)
-
-