org.eclipse.wst.server.core.model
Class ServerBehaviourDelegate

java.lang.Object
  extended byorg.eclipse.wst.server.core.model.ServerBehaviourDelegate

public abstract class ServerBehaviourDelegate
extends java.lang.Object

A server delegate provides the implementation for various generic and server-type-specific operations for a specific type of server. A server delegate is specified by the class attribute of a serverTypes extension.

When the server instance needs to be given a delegate, the delegate class specified for the server type is instantiated with a 0-argument constructor and primed with delegate.initialize(((IServerState)server), which it is expected to hang on to. Later, when delegate.dispose() is called as the server instance is being discarded, the delegate is expected to let go of the server instance.

Server delegates may keep state in instance fields, but that state is transient and will not be persisted across workbench sessions.

This abstract class is intended to be extended only by clients to extend the serverTypes extension point.

Caveat: The server core API is still in an early form, and is likely to change significantly before the initial release.

Since:
1.0
See Also:
IServer, IServerWorkingCopy

Field Summary
static int ADDED
          Publish kind constant (value 1) for added resources.
static int CHANGED
          Publish kind constant (value 2) for changed resources.
static int NO_CHANGE
          Publish kind constant (value 0) for no change.
static int REMOVED
          Publish kind constant (value 3) for removed resources.
 
Constructor Summary
ServerBehaviourDelegate()
          Delegates must have a public 0-arg constructor.
 
Method Summary
 boolean canRestartModule(IModule[] module)
          Returns whether the given module can be restarted.
 void dispose()
          Disposes of this server delegate.
 IModuleResourceDelta[] getPublishedResourceDelta(IModule[] module)
          Returns the delta of the current module resources that have been published compared to the current state of the module.
 IModuleResource[] getPublishedResources(IModule[] module)
          Returns the module resources that have been published to the server.
 IServer getServer()
          Returns the server that this server delegate corresponds to.
 IPath getTempDirectory()
          Returns a temporary directory that the requestor can use throughout it's lifecycle.
 void initialize(org.eclipse.wst.server.core.internal.Server newServer)
          Initializes this server delegate with its life-long server instance.
 IStatus publish(int kind, IProgressMonitor monitor)
           
 void restart(java.lang.String launchMode)
          Restart this server.
 void restartModule(IModule[] module, IProgressMonitor monitor)
          Asynchronously restarts the given module on the server.
 void setMode(java.lang.String mode)
          Sets the ILaunchManager mode that the server is running in.
 void setModulePublishState(IModule[] module, int state)
          Sets the module publish state.
 void setModuleRestartState(IModule[] module, boolean state)
          Sets the module restart state.
 void setModuleState(IModule[] module, int state)
          Hook to fire an event when a module state changes.
 void setModuleStatus(IModule[] module, IStatus status)
          Set a status on a specific module.
 void setServerPublishState(int state)
          Sets the server publish state.
 void setServerRestartState(boolean state)
          Sets the server restart state.
 void setServerState(int state)
          Sets the current state of this server.
 void setServerStatus(IStatus status)
          Set a global status on the server.
 void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor)
          Configure the given launch configuration to start this server.
abstract  void stop(boolean force)
          Shuts down and stops this server.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_CHANGE

public static final int NO_CHANGE
Publish kind constant (value 0) for no change.

See Also:
#publishModule(int, int, IModule[], IProgressMonitor), Constant Field Values

ADDED

public static final int ADDED
Publish kind constant (value 1) for added resources.

See Also:
#publishModule(int, int, IModule[], IProgressMonitor), Constant Field Values

CHANGED

public static final int CHANGED
Publish kind constant (value 2) for changed resources.

See Also:
#publishModule(int, int, IModule[], IProgressMonitor), Constant Field Values

REMOVED

public static final int REMOVED
Publish kind constant (value 3) for removed resources.

See Also:
#publishModule(int, int, IModule[], IProgressMonitor), Constant Field Values
Constructor Detail

ServerBehaviourDelegate

public ServerBehaviourDelegate()
Delegates must have a public 0-arg constructor.

Method Detail

initialize

public final void initialize(org.eclipse.wst.server.core.internal.Server newServer)
Initializes this server delegate with its life-long server instance.

This method is called by the server core framework. Clients should never call this method.

Parameters:
newServer - the server instance

getServer

public final IServer getServer()
Returns the server that this server delegate corresponds to.

Returns:
the server

setServerState

public final void setServerState(int state)
Sets the current state of this server.

Parameters:
state - the current state of the server, one of the state constants defined by IServer
See Also:
IServer.getServerState()

setMode

public final void setMode(java.lang.String mode)
Sets the ILaunchManager mode that the server is running in. The server implementation will automatically return null to clients when the server is stopped, so you only need to update the mode when it changes.

Parameters:
mode - the mode in which a server is running, one of the mode constants defined by org.eclipse.debug.core.ILaunchManager

setServerRestartState

public final void setServerRestartState(boolean state)
Sets the server restart state.

Parameters:
state - true if the server needs to be restarted, and false otherwise

setServerPublishState

public final void setServerPublishState(int state)
Sets the server publish state.

Parameters:
state - the current publish state of the server, one of the publish constants defined by IServer

setModuleState

public final void setModuleState(IModule[] module,
                                 int state)
Hook to fire an event when a module state changes.

Parameters:
module - the module
state - the current state of the module, one of the state constants defined by IServer

setModulePublishState

public final void setModulePublishState(IModule[] module,
                                        int state)
Sets the module publish state.

Parameters:
module - the module
state - the current publish state of the module, one of the publish constants defined by IServer

setModuleRestartState

public final void setModuleRestartState(IModule[] module,
                                        boolean state)
Sets the module restart state.

Parameters:
module - the module
state - true if the module needs to be restarted, and false otherwise

dispose

public void dispose()
Disposes of this server delegate.

This method is called by the web server core framework. Clients should never call this method.

Implementations are expected to let go of the delegate's reference to the server, deregister listeners, etc.


setupLaunchConfiguration

public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy,
                                     IProgressMonitor monitor)
                              throws CoreException
Configure the given launch configuration to start this server. This method is called whenever the server is started to ensure that the launch configuration is accurate and up to date. This method should not blindly update the launch configuration in cases where the user has access to change the launch configuration by hand.

Parameters:
workingCopy - a launch configuration working copy
monitor - a progress monitor, or null if progress reporting and cancellation are not desired
Throws:
CoreException - if there is an error setting up the configuration

restart

public void restart(java.lang.String launchMode)
             throws CoreException
Restart this server. The server should use the server listener to notify progress. It must use the same debug flags as was originally passed into the start() method. This method is used if there is a quick/better way to restart the server. If it throws a CoreException, the normal stop/start actions will be used.

Parameters:
launchMode - the mode to restart in, one of the mode constants defined by org.eclipse.debug.core.ILaunchManager
Throws:
CoreException - if there was a problem restarting

canRestartModule

public boolean canRestartModule(IModule[] module)
Returns whether the given module can be restarted.

[issue: It's unclear whether this operations is guaranteed to be fast or whether it could involve communication with any actual server. If it is not fast, the method should take a progress monitor.]

Parameters:
module - the module
Returns:
true if the given module can be restarted, and false otherwise

restartModule

public void restartModule(IModule[] module,
                          IProgressMonitor monitor)
                   throws CoreException
Asynchronously restarts the given module on the server. See the specification of IServer.synchronousRestartModule(IModule[], IProgressMonitor) for further details.

The implementation should update the module sync state and fire an event for the module.

This method will throw an exception if the module does not exist on the server.

[issue: Since this method is ascynchronous, is there any need for the progress monitor?]

[issue: If the module was just published to the server and had never been started, would is be ok to "start" the module using this method?]

Parameters:
module - the module to be started
monitor - a progress monitor, or null if progress reporting and cancellation are not desired
Throws:
CoreException - if an error occurs while trying to restart the module

stop

public abstract void stop(boolean force)
Shuts down and stops this server. The server should return from this method quickly and use the server listener to notify shutdown progress.

If force is false, it will attempt to stop the server normally/gracefully. If force is true, then the server process will be terminated any way that it can.

[issue: There is no way to communicate failure to the client. Given that this operation can go awry, there probably should be a mechanism that allows failing asynch operations to be diagnosed.]

Parameters:
force - true to kill the server, or false to stop normally

getPublishedResources

public IModuleResource[] getPublishedResources(IModule[] module)
Returns the module resources that have been published to the server.

If the module has just been added to the server, an empty list will be returned. If the module has never existed on the server, a CoreException will be thrown.

Parameters:
module - the module
Returns:
an array containing the published module resource

getPublishedResourceDelta

public IModuleResourceDelta[] getPublishedResourceDelta(IModule[] module)
Returns the delta of the current module resources that have been published compared to the current state of the module.

Parameters:
module - the module
Returns:
an array containing the publish resource delta

getTempDirectory

public final IPath getTempDirectory()
Returns a temporary directory that the requestor can use throughout it's lifecycle. This is primary to be used by servers for working directories, server specific files, etc.

This method directory will return the same directory on each use of the workbench. If the directory is not requested over a period of time, the directory may be deleted and a new one will be assigned on the next request. For this reason, a server may want to request the temp directory on startup if it wants to store files there. In any case, the server should have a backup plan to refill the directory in case it has been deleted since last use.

Returns:
a temporary directory

setServerStatus

public final void setServerStatus(IStatus status)
Set a global status on the server.

Parameters:
status - the status

setModuleStatus

public final void setModuleStatus(IModule[] module,
                                  IStatus status)
Set a status on a specific module.

Parameters:
module - the module
status - the status

publish

public IStatus publish(int kind,
                       IProgressMonitor monitor)