tools.rmiserver
Class JinniRmiImpl

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by tools.rmiserver.JinniRmiImpl
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, IJinniEngine

public class JinniRmiImpl
extends java.rmi.server.UnicastRemoteObject
implements IJinniEngine

This is the implementation of the IJinniEngine for the JinnIde server. This is a kind of RMI wrapper redirecting the calls to embedded IJinniEngine - either a JinniPrologEngine or a JinniPureEngine.

Version:
Clide
Author:
Wolfgang Chico Toepfer
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface tools.jinnide.IJinniEngine
IJinniEngine.EngineState
 
Field Summary
 java.lang.String defaultPortNr
           
 
Constructor Summary
JinniRmiImpl()
           
 
Method Summary
 java.lang.String consult(java.lang.String filePath)
          consults a file
 java.lang.String getInitializationFile()
          find out the name of the initialization file used to start up the Jinni engine
 java.lang.String getJinniOutput()
          this one is implemented by all the specialization classes because it includes getting the output (but not the direct feedback)
 java.lang.String getLibraryPath()
          find out the path of the current Jinni engine's system library
 JinniEngineAnswer getQuery(java.lang.String validator, java.lang.String value)
          asks a question to Jinni and returns a Jinni solution, which is only the first solution in foreground mode returned as a JinniEngineAnswer so focussed on true/false validation
 JinniEngineAnswer getSimpleQuery(java.lang.String validator, java.lang.String value)
          asks a question to Jinni and returns a Jinni solution, which is only the first solution in foreground mode returned as a JinniEngineAnswer so focussed on true/false validation
 java.lang.String getStartupFeedback()
          Returns and sets engine feedback as a by result of a query, usually the first consulting query to load the lib
 IJinniEngine.EngineState getState()
          Informs the client of this engine's state
 java.lang.String getVersion()
           
 void halt()
          this is one of a couple of reset methods for the Jinni server process (only halt affects the RMI server process ) such as reset which does an internal reset of the Jinni engine, should be used with care
 boolean isAllModeUsed()
          find out if the all mode is active
 boolean isBackgroundModeUsed()
          find out if the background mode is active
 boolean isPrologModeUsed()
          find out if the prolog mode is active
 boolean isTraceModeUsed()
          find out if the usual prolog trace mode is active
 java.lang.String jinnidoc(java.lang.String directoryPath)
          generates a documentation for a whole directory
 java.lang.String jinnidoc(java.lang.String filePath, java.lang.String filename)
          generates a documentation for a file
 void kill()
          kill this server process by force despite pending client requests
 java.lang.String listing()
          lists the current clauses in the current Jinni engine instance
 java.lang.String loadEngine()
          loads the engine with classpaths, consults etc.; is implicitly done in startupEngine
 java.lang.String more()
          returns the next solution if available otherwise no
 JinniEngineAnswer moreAsAnswer()
          returns the next solution as a JinniEngineAnswer if available otherwise no
static void output(java.lang.String message)
           
 java.lang.String query(java.lang.String query)
          asks a question to Jinni and returns a Jinni solution, which is either all solutions in case of using the all mode, or otherwise just the first solution
 java.lang.String reconsult(java.lang.String filePath)
          reconsult a file
 java.lang.String renew(java.lang.String objectName)
          renew a Jinni object
 java.lang.String renewLoq4Jinni()
          renews Loq4Jinni's state to update to another logging level which is set otherwise
 java.lang.String reset()
          does an internal restart of the current Jinni engine
 java.lang.String restart()
          restarts the Jinni server process without affecting the RMI server process
 void setAllMode(boolean isAllModeUsed)
          allows switching between the usual prolog solution by solution mode and getting all solutions at once which is when isAllModeUsed must be true
 void setBackgroundMode()
          allows switching on and off the background mode which allows running a query on the server in a separate thread while other queries may be answered in sort-of the same time while the other query is still running; There is no server-side usage because a JinniProlog server is actually a rather different alternative with its own advantages (and drwabacks ;), thus it would not implement this method (actually we could move this declaration to an abstract method somewhere below this interface).
 void setInitializationFile(java.lang.String filename)
          sets the name of the file that is supposed to lie in the library set by setLibraryPath, if not set "init.pro" is assumed
 void setJinniOutput(javax.swing.JTextArea jta)
          sets the text area that is used to insert all the output that is not the direct feedback of a query; if this method is not called, a default JTextArea is used
 void setLibraryPath(java.lang.String path)
          set developer library path where on the first level an initialization file resides that is consulted by loadEngine which is all loadEngine actually does; if not set, the directory relative to this class library is assumed
 void setPrologMode(boolean isPrologModeUsed)
          choose between a prolog mode which is the JinniPrologEngine and the pure mode which is the JinniPureEngine
 void setStartupFeedback(java.lang.String feedback)
           
 void setTraceMode(boolean isTraceModeUsed)
          allows switching on the usual prolog trace mode
 java.lang.String startupEngine()
          starts up the default engine (without providing setup parameters)
 java.lang.String startupEngine(java.lang.String[] params)
          starts up the engine
 java.lang.String stopEngine()
          stops the engine and thus sets the system back to its initial state including a possibly running thread that is also stopped
 java.lang.String stopThread()
          this one is implemented by all the specialization classes because it includes stopping the specific machine
 void terminate()
          kill this server process gently
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultPortNr

public java.lang.String defaultPortNr
Constructor Detail

JinniRmiImpl

public JinniRmiImpl()
             throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException
Method Detail

getStartupFeedback

public java.lang.String getStartupFeedback()
                                    throws java.rmi.RemoteException,
                                           JinniEngineException
Description copied from interface: IJinniEngine
Returns and sets engine feedback as a by result of a query, usually the first consulting query to load the lib

Specified by:
getStartupFeedback in interface IJinniEngine
Returns:
feedback produced during startup of the engine most probably as a result of consulting a lib
Throws:
java.rmi.RemoteException
JinniEngineException

output

public static void output(java.lang.String message)

getVersion

public java.lang.String getVersion()
                            throws java.rmi.RemoteException
Specified by:
getVersion in interface IJinniEngine
Returns:
current version of Jinni used
Throws:
java.rmi.RemoteException

kill

public void kill()
          throws java.rmi.RemoteException,
                 java.rmi.NotBoundException,
                 java.rmi.NoSuchObjectException,
                 JinniEngineException,
                 java.net.MalformedURLException,
                 java.rmi.NotBoundException
kill this server process by force despite pending client requests

Specified by:
kill in interface IJinniEngine
Throws:
java.rmi.NotBoundException
java.net.MalformedURLException
JinnIdeGeneralExecutorException
java.rmi.RemoteException
java.rmi.NoSuchObjectException
JinniEngineException

terminate

public void terminate()
               throws java.rmi.RemoteException,
                      java.rmi.NoSuchObjectException,
                      JinniEngineException,
                      java.net.MalformedURLException,
                      java.rmi.NotBoundException
kill this server process gently

Specified by:
terminate in interface IJinniEngine
Throws:
java.rmi.NotBoundException
java.net.MalformedURLException
java.rmi.RemoteException
java.rmi.NoSuchObjectException
JinniEngineException

consult

public java.lang.String consult(java.lang.String filePath)
                         throws java.rmi.RemoteException,
                                JinniEngineException
Description copied from interface: IJinniEngine
consults a file

Specified by:
consult in interface IJinniEngine
Parameters:
filePath - path to the file/directory to be consulted
Returns:
consult the given file, returns jinni's answer on this query; note that a '/' or '\' suffix indicates that a whole directory is going to be consulted
Throws:
JinniEngineException
java.rmi.RemoteException

getInitializationFile

public java.lang.String getInitializationFile()
                                       throws java.rmi.RemoteException
Description copied from interface: IJinniEngine
find out the name of the initialization file used to start up the Jinni engine

Specified by:
getInitializationFile in interface IJinniEngine
Returns:
the name of the initialization file see setInitializationFile
Throws:
java.rmi.RemoteException

getLibraryPath

public java.lang.String getLibraryPath()
                                throws java.rmi.RemoteException
Description copied from interface: IJinniEngine
find out the path of the current Jinni engine's system library

Specified by:
getLibraryPath in interface IJinniEngine
Returns:
returns the current library path, see setLibraryPath
Throws:
java.rmi.RemoteException

halt

public void halt()
          throws JinniEngineException,
                 java.net.MalformedURLException,
                 java.rmi.NotBoundException
Description copied from interface: IJinniEngine
this is one of a couple of reset methods for the Jinni server process (only halt affects the RMI server process ) such as reset which does an internal reset of the Jinni engine, should be used with care

Specified by:
halt in interface IJinniEngine
Throws:
JinniEngineException
java.net.MalformedURLException
java.rmi.NotBoundException

isAllModeUsed

public boolean isAllModeUsed()
                      throws java.rmi.RemoteException
Description copied from interface: IJinniEngine
find out if the all mode is active

Specified by:
isAllModeUsed in interface IJinniEngine
Returns:
true iff the all mode is active
Throws:
java.rmi.RemoteException

isPrologModeUsed

public boolean isPrologModeUsed()
                         throws JinniEngineException,
                                java.rmi.RemoteException
Description copied from interface: IJinniEngine
find out if the prolog mode is active

Specified by:
isPrologModeUsed in interface IJinniEngine
Returns:
true iff the prolog mode is active
Throws:
JinniEngineException
java.rmi.RemoteException

isBackgroundModeUsed

public boolean isBackgroundModeUsed()
                             throws java.rmi.RemoteException
Description copied from interface: IJinniEngine
find out if the background mode is active

Specified by:
isBackgroundModeUsed in interface IJinniEngine
Returns:
true iff the background mode is active
Throws:
java.rmi.RemoteException

isTraceModeUsed

public boolean isTraceModeUsed()
                        throws java.rmi.RemoteException
Description copied from interface: IJinniEngine
find out if the usual prolog trace mode is active

Specified by:
isTraceModeUsed in interface IJinniEngine
Returns:
true iff the trace is active
Throws:
java.rmi.RemoteException

jinnidoc

public java.lang.String jinnidoc(java.lang.String filePath,
                                 java.lang.String filename)
                          throws java.rmi.RemoteException,
                                 JinniEngineException
Description copied from interface: IJinniEngine
generates a documentation for a file

Specified by:
jinnidoc in interface IJinniEngine
Parameters:
filePath - path to the file to be documented
filename - name of the file to be documented
Returns:
generates a documentation for the given file, returns the query response
Throws:
JinniEngineException
java.rmi.RemoteException

jinnidoc

public java.lang.String jinnidoc(java.lang.String directoryPath)
                          throws java.rmi.RemoteException,
                                 JinniEngineException
Description copied from interface: IJinniEngine
generates a documentation for a whole directory

Specified by:
jinnidoc in interface IJinniEngine
Parameters:
directoryPath - path to the directory to be documented
Returns:
generates a documentation for a whole directory, returns the query response
Throws:
JinniEngineException
java.rmi.RemoteException

listing

public java.lang.String listing()
                         throws java.rmi.RemoteException,
                                JinniEngineException
Description copied from interface: IJinniEngine
lists the current clauses in the current Jinni engine instance

Specified by:
listing in interface IJinniEngine
Returns:
returns all the current clauses in the current jinni engine
Throws:
JinniEngineException
java.rmi.RemoteException

loadEngine

public java.lang.String loadEngine()
                            throws java.rmi.RemoteException,
                                   JinniEngineException
Description copied from interface: IJinniEngine
loads the engine with classpaths, consults etc.; is implicitly done in startupEngine

Specified by:
loadEngine in interface IJinniEngine
Returns:
Jinni's feedback message
Throws:
JinniEngineException
java.rmi.RemoteException

more

public java.lang.String more()
                      throws java.rmi.RemoteException,
                             JinniEngineException
Description copied from interface: IJinniEngine
returns the next solution if available otherwise no

Specified by:
more in interface IJinniEngine
Returns:
Jinni's query response when being asked for a further solution
Throws:
JinniEngineException
java.rmi.RemoteException

query

public java.lang.String query(java.lang.String query)
                       throws java.rmi.RemoteException,
                              JinniEngineException
Description copied from interface: IJinniEngine
asks a question to Jinni and returns a Jinni solution, which is either all solutions in case of using the all mode, or otherwise just the first solution

Specified by:
query in interface IJinniEngine
Parameters:
query - the query to be asked
Returns:
Jinni's query response
Throws:
JinniEngineException
java.rmi.RemoteException

reconsult

public java.lang.String reconsult(java.lang.String filePath)
                           throws java.rmi.RemoteException,
                                  JinniEngineException
Description copied from interface: IJinniEngine
reconsult a file

Specified by:
reconsult in interface IJinniEngine
Parameters:
filePath - path to the file/directory to be reconsulted
Returns:
reconsult the given file, returns jinni's answer on this query; note that a '/' or '\' suffix indicates that a whole directory is going to be reconsulted
Throws:
JinniEngineException
java.rmi.RemoteException

renew

public java.lang.String renew(java.lang.String objectName)
                       throws java.rmi.RemoteException,
                              JinniEngineException
Description copied from interface: IJinniEngine
renew a Jinni object

Specified by:
renew in interface IJinniEngine
Parameters:
objectName - name of the object to be renewed
Returns:
renew a Jinni object i.e. updates the class object information and so allows creating new instances with an updated version of the Jinni object, returns Jinni's response
Throws:
JinniEngineException
java.rmi.RemoteException

renewLoq4Jinni

public java.lang.String renewLoq4Jinni()
                                throws java.rmi.RemoteException,
                                       JinniEngineException
Description copied from interface: IJinniEngine
renews Loq4Jinni's state to update to another logging level which is set otherwise

Specified by:
renewLoq4Jinni in interface IJinniEngine
Returns:
allows switching the logging level of Loq4Jinni, returns Jinni's response
Throws:
JinniEngineException
java.rmi.RemoteException

reset

public java.lang.String reset()
                       throws java.rmi.RemoteException,
                              JinniEngineException
Description copied from interface: IJinniEngine
does an internal restart of the current Jinni engine

Specified by:
reset in interface IJinniEngine
Returns:
the query response regarding the success or failure of the mode switch
Throws:
JinniEngineException
java.rmi.RemoteException

restart

public java.lang.String restart()
                         throws java.rmi.RemoteException,
                                JinniEngineException
Description copied from interface: IJinniEngine
restarts the Jinni server process without affecting the RMI server process

Specified by:
restart in interface IJinniEngine
Returns:
the query response regarding the success or failure of the mode switch
Throws:
JinniEngineException
java.rmi.RemoteException

setAllMode

public void setAllMode(boolean isAllModeUsed)
                throws java.rmi.RemoteException
Description copied from interface: IJinniEngine
allows switching between the usual prolog solution by solution mode and getting all solutions at once which is when isAllModeUsed must be true

Specified by:
setAllMode in interface IJinniEngine
Parameters:
isAllModeUsed - actual switch value to be set
Throws:
java.rmi.RemoteException

setBackgroundMode

public void setBackgroundMode()
                       throws java.rmi.RemoteException,
                              JinniEngineException
Description copied from interface: IJinniEngine
allows switching on and off the background mode which allows running a query on the server in a separate thread while other queries may be answered in sort-of the same time while the other query is still running; There is no server-side usage because a JinniProlog server is actually a rather different alternative with its own advantages (and drwabacks ;), thus it would not implement this method (actually we could move this declaration to an abstract method somewhere below this interface).

Specified by:
setBackgroundMode in interface IJinniEngine
Throws:
java.rmi.RemoteException
JinniEngineException

setInitializationFile

public void setInitializationFile(java.lang.String filename)
                           throws java.rmi.RemoteException,
                                  JinniEngineException
Description copied from interface: IJinniEngine
sets the name of the file that is supposed to lie in the library set by setLibraryPath, if not set "init.pro" is assumed

Specified by:
setInitializationFile in interface IJinniEngine
Parameters:
filename - name of the initialization file
Throws:
JinniEngineException
java.rmi.RemoteException

setLibraryPath

public void setLibraryPath(java.lang.String path)
                    throws java.rmi.RemoteException,
                           JinniEngineException
Description copied from interface: IJinniEngine
set developer library path where on the first level an initialization file resides that is consulted by loadEngine which is all loadEngine actually does; if not set, the directory relative to this class library is assumed

Specified by:
setLibraryPath in interface IJinniEngine
Parameters:
path - path to the JinnIde sytem library
Throws:
JinniEngineException
java.rmi.RemoteException

setPrologMode

public void setPrologMode(boolean isPrologModeUsed)
                   throws java.rmi.RemoteException,
                          JinniEngineException
Description copied from interface: IJinniEngine
choose between a prolog mode which is the JinniPrologEngine and the pure mode which is the JinniPureEngine

Specified by:
setPrologMode in interface IJinniEngine
Parameters:
isPrologModeUsed - actual switch value to be set
Throws:
java.rmi.RemoteException
JinniEngineException

setTraceMode

public void setTraceMode(boolean isTraceModeUsed)
                  throws java.rmi.RemoteException,
                         JinniEngineException
Description copied from interface: IJinniEngine
allows switching on the usual prolog trace mode

Specified by:
setTraceMode in interface IJinniEngine
Parameters:
isTraceModeUsed - actual switch value to be set
Throws:
java.rmi.RemoteException
JinniEngineException

startupEngine

public java.lang.String startupEngine(java.lang.String[] params)
                               throws java.rmi.RemoteException,
                                      JinniEngineException
Description copied from interface: IJinniEngine
starts up the engine

Specified by:
startupEngine in interface IJinniEngine
Parameters:
params - Jinni initialization parameters that may be set here
Returns:
returns some initial feedback
Throws:
JinniEngineException
java.rmi.RemoteException

stopEngine

public java.lang.String stopEngine()
                            throws java.rmi.RemoteException,
                                   JinniEngineException
Description copied from interface: IJinniEngine
stops the engine and thus sets the system back to its initial state including a possibly running thread that is also stopped

Specified by:
stopEngine in interface IJinniEngine
Returns:
the query response regarding the success or failure of the mode switch
Throws:
JinniEngineException
java.rmi.RemoteException

stopThread

public java.lang.String stopThread()
                            throws java.rmi.RemoteException,
                                   JinniEngineException
Description copied from interface: IJinniEngine
this one is implemented by all the specialization classes because it includes stopping the specific machine

Specified by:
stopThread in interface IJinniEngine
Returns:
the query response regarding the success or failure of the stop process
Throws:
JinniEngineException
java.rmi.RemoteException

getJinniOutput

public java.lang.String getJinniOutput()
                                throws java.rmi.RemoteException,
                                       JinniEngineException
Description copied from interface: IJinniEngine
this one is implemented by all the specialization classes because it includes getting the output (but not the direct feedback)

Specified by:
getJinniOutput in interface IJinniEngine
Returns:
the part of a query response that is directed to the Jinni output stream
Throws:
JinniEngineException
java.rmi.RemoteException

setJinniOutput

public void setJinniOutput(javax.swing.JTextArea jta)
                    throws JinniEngineException
Description copied from interface: IJinniEngine
sets the text area that is used to insert all the output that is not the direct feedback of a query; if this method is not called, a default JTextArea is used

Specified by:
setJinniOutput in interface IJinniEngine
Parameters:
jta - the text area to be used to keep the output of a Jinni instance
Throws:
JinniEngineException

getSimpleQuery

public JinniEngineAnswer getSimpleQuery(java.lang.String validator,
                                        java.lang.String value)
                                 throws JinniEngineException,
                                        java.rmi.RemoteException
Description copied from interface: IJinniEngine
asks a question to Jinni and returns a Jinni solution, which is only the first solution in foreground mode returned as a JinniEngineAnswer so focussed on true/false validation

Specified by:
getSimpleQuery in interface IJinniEngine
Parameters:
validator - the validator to be used which is an indication of the desired validation predicate e.g. "validate" or "askItSomething"
value - the value to be validated e.g. a number (passed as a String)
Returns:
Jinni's response wrapped up in a JinniEngineAnswer instance
Throws:
JinniEngineException
java.rmi.RemoteException

getQuery

public JinniEngineAnswer getQuery(java.lang.String validator,
                                  java.lang.String value)
                           throws JinniEngineException,
                                  java.rmi.RemoteException
Description copied from interface: IJinniEngine
asks a question to Jinni and returns a Jinni solution, which is only the first solution in foreground mode returned as a JinniEngineAnswer so focussed on true/false validation

Specified by:
getQuery in interface IJinniEngine
Parameters:
validator - the validator to be used which is an indication of the validation module and the desired validation predicate e.g. "validator:validate" or "validator:askMeSomething"; its syntax is idential with Jinni's module predicate call syntax so always uses a colon to separate the module from the predicate
value - the value to be validated
Returns:
Jinni's response wrapped up in a JinniEngineAnswer instance
Throws:
JinniEngineException
java.rmi.RemoteException

moreAsAnswer

public JinniEngineAnswer moreAsAnswer()
                               throws JinniEngineException,
                                      java.rmi.RemoteException
Description copied from interface: IJinniEngine
returns the next solution as a JinniEngineAnswer if available otherwise no

Specified by:
moreAsAnswer in interface IJinniEngine
Returns:
Jinni's query response wrapped up as a JinniEngineAnswer instance when being asked for a further solution
Throws:
JinniEngineException
java.rmi.RemoteException

startupEngine

public java.lang.String startupEngine()
                               throws JinniEngineException,
                                      java.rmi.RemoteException
Description copied from interface: IJinniEngine
starts up the default engine (without providing setup parameters)

Specified by:
startupEngine in interface IJinniEngine
Returns:
returns some initial feedback
Throws:
JinniEngineException
java.rmi.RemoteException

getState

public IJinniEngine.EngineState getState()
                                  throws java.rmi.RemoteException
Description copied from interface: IJinniEngine
Informs the client of this engine's state

Specified by:
getState in interface IJinniEngine
Throws:
java.rmi.RemoteException

setStartupFeedback

public void setStartupFeedback(java.lang.String feedback)
                        throws java.rmi.RemoteException,
                               JinniEngineException
Specified by:
setStartupFeedback in interface IJinniEngine
Throws:
java.rmi.RemoteException
JinniEngineException