org.abstracthorizon.extend.server.deployment.support
Class DeploymentDirectoryModule

java.lang.Object
  extended by org.abstracthorizon.extend.server.deployment.support.DeploymentDirectoryModule
All Implemented Interfaces:
Runnable, Module

public class DeploymentDirectoryModule
extends Object
implements Module, Runnable

This module scans given URL for changes and then deploys/undeploys/redeploys modules added/removed/changed to it. It uses KernelScheduler for intervals for scanning.

Author:
Daniel Sendula

Field Summary
protected  LinkedHashSet<Module> dependOnThis
          List of modules that depend on this
protected  HashMap<File,Long> files
          Map of files' last changed time from supplied directory
protected  URL location
          Original location url
protected  DeploymentManager manager
          Deployment manager everything is executed from
protected  ModuleId moduleId
          Module name
protected  File path
          Path
protected  SimpleScheduler scheduler
          Scheduler to check changes in this directory
protected  int state
          Module state
 
Fields inherited from interface org.abstracthorizon.extend.server.deployment.Module
CREATED, DEFINED, STARTED, UNDEFINED, WAITING_ON_CREATE, WAITING_ON_CREATE_TO_START, WAITING_ON_START
 
Constructor Summary
DeploymentDirectoryModule()
          Empty constructor
 
Method Summary
 void create()
          Does nothing
 void deploy(File file)
          Deploys file loading module through main deployer DeploymentManager.
 void destroy()
          Trys to undeploy files that were watched over
 boolean equals(Object o)
          Compares two modules and returns true if names are the same
 ClassLoader getClassLoader()
          Returns null.
 Set<Module> getDependOnThis()
          Returns set of modules that depend on this.
 Set<Module> getDependsOn()
          Returns an empty set.
 DeploymentManager getDeploymentManager()
          Returns main deployer (DeploymentManager);
 ModuleId getModuleId()
          Returns module's id
 URL getOriginalLocation()
          Returns original location url.
 SimpleScheduler getScheduler()
          Returns scheduler (SimpleScheduler)
protected  SimpleScheduler getSchedulerInternal()
          This method is used internally for scheduler to be obtained.
 int getState()
          Returns module's state
 String getStateAsString()
          Returns module's state as a string
 URL getWorkingLocation()
          Returns working location url.
 void redeploy(File file)
          Re-deploys file finding module through main deployer DeploymentManager.
protected  void rescan()
          Scans given directory for changes.
 void run()
          Calls rescan().
 void setDeploymentManager(DeploymentManager manager)
          Sets main deployer (DeploymentManager);
 void setLocation(File file)
          Sets location as a file
 void setLocation(URL location)
          Sets location.
 void setModuleId(ModuleId moduleId)
          Sets module's id
 void setScheduler(SimpleScheduler scheduler)
          Sets scheduler (SimpleScheduler).
 void setState(int state)
          Sets module's state
 void start()
          Start scheduler over this directory
 void stop()
          Stops scheduler
 void undeploy(File file)
          Undeploys file finding module through main deployer DeploymentManager.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

moduleId

protected ModuleId moduleId
Module name


path

protected File path
Path


location

protected URL location
Original location url


state

protected int state
Module state


dependOnThis

protected LinkedHashSet<Module> dependOnThis
List of modules that depend on this


scheduler

protected SimpleScheduler scheduler
Scheduler to check changes in this directory


files

protected HashMap<File,Long> files
Map of files' last changed time from supplied directory


manager

protected DeploymentManager manager
Deployment manager everything is executed from

Constructor Detail

DeploymentDirectoryModule

public DeploymentDirectoryModule()
Empty constructor

Method Detail

getClassLoader

public ClassLoader getClassLoader()
Returns null.

Specified by:
getClassLoader in interface Module
Returns:
null

getDependOnThis

public Set<Module> getDependOnThis()
Returns set of modules that depend on this.

Specified by:
getDependOnThis in interface Module
Returns:
set of modules that depend on this

getDependsOn

public Set<Module> getDependsOn()
Returns an empty set.

Specified by:
getDependsOn in interface Module
Returns:
en empty set

getOriginalLocation

public URL getOriginalLocation()
Returns original location url.

Specified by:
getOriginalLocation in interface Module
Returns:
original location url

getWorkingLocation

public URL getWorkingLocation()
Returns working location url.

Specified by:
getWorkingLocation in interface Module
Returns:
working location url

setLocation

public void setLocation(URL location)
Sets location.

Parameters:
location - location
Throws:
RuntimeException - if url is not of file protocol and file part is not ending with "/"

setLocation

public void setLocation(File file)
Sets location as a file

Parameters:
file - directory
Throws:
RuntimeException - if file is not a directory

getModuleId

public ModuleId getModuleId()
Returns module's id

Specified by:
getModuleId in interface Module
Returns:
module's id

setModuleId

public void setModuleId(ModuleId moduleId)
Sets module's id

Parameters:
moduelId - module's id

create

public void create()
Does nothing

Specified by:
create in interface Module

start

public void start()
Start scheduler over this directory

Specified by:
start in interface Module

stop

public void stop()
Stops scheduler

Specified by:
stop in interface Module

destroy

public void destroy()
Trys to undeploy files that were watched over

Specified by:
destroy in interface Module

run

public void run()
Calls rescan().

Specified by:
run in interface Runnable

rescan

protected void rescan()
Scans given directory for changes. If file is new it is going to be deployed through main deployer DeploymentManager. If file already existed and last changed time is changed it is going to be redeployed.


deploy

public void deploy(File file)
Deploys file loading module through main deployer DeploymentManager.

Parameters:
file - file to be deployed

redeploy

public void redeploy(File file)
Re-deploys file finding module through main deployer DeploymentManager.

Parameters:
file - file to be redeployed

undeploy

public void undeploy(File file)
Undeploys file finding module through main deployer DeploymentManager.

Parameters:
file - file to be undeployed

setState

public void setState(int state)
Sets module's state

Specified by:
setState in interface Module
Parameters:
state - module's state

getState

public int getState()
Returns module's state

Specified by:
getState in interface Module
Returns:
module's state

getStateAsString

public String getStateAsString()
Returns module's state as a string

Returns:
module's state as a string

setScheduler

public void setScheduler(SimpleScheduler scheduler)
Sets scheduler (SimpleScheduler).

Parameters:
scheduler - scheduler

getScheduler

public SimpleScheduler getScheduler()
Returns scheduler (SimpleScheduler)

Returns:
scheduler

getSchedulerInternal

protected SimpleScheduler getSchedulerInternal()
This method is used internally for scheduler to be obtained. If scheduler is not assigned then KernelScheduler is going to be used.

Returns:
scheduler or newly created scheduler

getDeploymentManager

public DeploymentManager getDeploymentManager()
Returns main deployer (DeploymentManager);

Returns:
main deployer (DeploymentManager);

setDeploymentManager

public void setDeploymentManager(DeploymentManager manager)
Sets main deployer (DeploymentManager);

Parameters:
manager - main deployer (DeploymentManager);

equals

public boolean equals(Object o)
Compares two modules and returns true if names are the same

Overrides:
equals in class Object
Parameters:
o - other object
Returns:
true if names are the same


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.