Crossfire JXClient, Trunk
Classes | Public Member Functions | Static Public Attributes | Package Functions | Package Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
com.sun.jmx.examples.scandir.DirectoryScanner Class Reference
Inheritance diagram for com.sun.jmx.examples.scandir.DirectoryScanner:
Inheritance graph
Collaboration diagram for com.sun.jmx.examples.scandir.DirectoryScanner:
Collaboration graph

Classes

class  ScanTask
 

Public Member Functions

void addNotificationListener (NotificationListener listener, NotificationFilter filter, Object handback) throws IllegalArgumentException
 
 DirectoryScanner (DirectoryScannerConfig config, ResultLogManager logManager) throws IllegalArgumentException
 
DirectoryScannerConfig getConfiguration ()
 
String getCurrentScanInfo ()
 
MBeanNotificationInfo[] getNotificationInfo ()
 
String getRootDirectory ()
 
ScanState getState ()
 
void removeNotificationListener (NotificationListener listener) throws ListenerNotFoundException
 
void removeNotificationListener (NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException
 
void scan ()
 
void stop ()
 

Static Public Attributes

static final String FILE_MATCHES_NOTIFICATION
 

Package Functions

void actOn (File file)
 

Package Attributes

final Set< Actionactions
 
final ResultLogManager logManager
 

Private Member Functions

boolean deleteFile (File file)
 
boolean logResult (File file, Action[] actions)
 
boolean notifyMatch (File file)
 
void scan (ScanTask task, LinkedList< File > list)
 
final void setStateAndNotify (ScanState desired)
 

Static Private Member Functions

static File validateRoot (String root)
 

Private Attributes

final NotificationBroadcasterSupport broadcaster
 
final DirectoryScannerConfig config
 
volatile ScanTask currentTask = null
 
final File rootFile
 
volatile ScanState state = STOPPED
 

Static Private Attributes

static final Logger LOG
 

Detailed Description

A DirectoryScanner is an MBean that scans a file system starting at a given root directory, and then looks for files that match a given criteria.

When such a file is found, the DirectoryScanner takes the action for which it was configured: emit a notification, and or log a {} for this file, and or delete that file.

The code that would actually delete the file is commented out - so that nothing valuable is lost if this example is run by mistake on the wrong set of directories.
Logged results are logged by sending them to the ResultLogManager.

DirectoryScannerMXBeans are created, initialized, and registered by the ScanManagerMXBean. The ScanManagerMXBean will also schedule and run them in background by calling their scan method.

Client code is not expected to create or register directly any such MBean. Instead, clients are expected to modify the configuration, using the ScanDirConfigMXBean, and then apply it, using the {}. Instances of DirectoryScannerMXBeans will then be created and registered (or unregistered and garbage collected) as a side effect of applying that configuration.

Author
Sun Microsystems, 2006 - All rights reserved.

Definition at line 105 of file DirectoryScanner.java.

Constructor & Destructor Documentation

◆ DirectoryScanner()

com.sun.jmx.examples.scandir.DirectoryScanner.DirectoryScanner ( DirectoryScannerConfig  config,
ResultLogManager  logManager 
) throws IllegalArgumentException

Constructs a new

.

This constructor is package protected, and this MBean cannot be created by a remote client, because it needs a reference to the ResultLogManager, which cannot be provided from remote.

This is a conscious design choice:

MBeans are expected to be completely managed (created, registered, unregistered) by the ScanManager which does provide this reference.

Parameters
configThis configuration.
logManagerThe info log manager with which to log the info records.
Exceptions
IllegalArgumentExceptionif one of the parameter is null, or if the provided doesn't have its set, or if the root directory provided in the is not acceptable (not provided or not found or not readable, etc...).

Definition at line 178 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.actions, com.sun.jmx.examples.scandir.DirectoryScanner.broadcaster, com.sun.jmx.examples.scandir.DirectoryScanner.config, com.sun.jmx.examples.scandir.DirectoryScanner.logManager, com.sun.jmx.examples.scandir.DirectoryScanner.rootFile, com.sun.jmx.examples.scandir.DirectoryScanner.validateRoot(), and com.sun.jmx.examples.scandir.config.XmlConfigUtils.xmlClone().

Here is the call graph for this function:

Member Function Documentation

◆ actOn()

void com.sun.jmx.examples.scandir.DirectoryScanner.actOn ( File  file)
package

◆ addNotificationListener()

void com.sun.jmx.examples.scandir.DirectoryScanner.addNotificationListener ( NotificationListener  listener,
NotificationFilter  filter,
Object  handback 
) throws IllegalArgumentException

MBeanNotification support - delegates to broadcaster.

Definition at line 514 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.broadcaster.

◆ deleteFile()

boolean com.sun.jmx.examples.scandir.DirectoryScanner.deleteFile ( File  file)
private

Definition at line 337 of file DirectoryScanner.java.

References file, and com.sun.jmx.examples.scandir.DirectoryScanner.LOG.

Referenced by com.sun.jmx.examples.scandir.DirectoryScanner.actOn().

Here is the caller graph for this function:

◆ getConfiguration()

DirectoryScannerConfig com.sun.jmx.examples.scandir.DirectoryScanner.getConfiguration ( )

The configuration data from which this DirectoryScanner was created.

You cannot change this configuration here. You can however modify the ScanDirConfigMXBean configuration, and ask the ScanManagerMXBean to apply it. This will get all DirectoryScannerMXBean replaced by new MBeans created from the modified configuration.

Returns
This DirectoryScannerMXBean configuration data.
Exceptions
IOExceptionA connection problem occurred when accessing the underlying resource.
InstanceNotFoundExceptionThe underlying MBean is not registered in the MBeanServer.

Implements com.sun.jmx.examples.scandir.DirectoryScannerMXBean.

Definition at line 227 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.config.

◆ getCurrentScanInfo()

String com.sun.jmx.examples.scandir.DirectoryScanner.getCurrentScanInfo ( )

A short string describing what's happening in current/latest scan.

Returns
a short info string.
Exceptions
IOExceptionA connection problem occurred when accessing the underlying resource.
InstanceNotFoundExceptionThe underlying MBean is not registered in the MBeanServer.

Implements com.sun.jmx.examples.scandir.DirectoryScannerMXBean.

Definition at line 232 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.currentTask, and com.sun.jmx.examples.scandir.DirectoryScanner.ScanTask.getScanInfo().

Here is the call graph for this function:

◆ getNotificationInfo()

MBeanNotificationInfo [] com.sun.jmx.examples.scandir.DirectoryScanner.getNotificationInfo ( )

The DirectoryScannerMXBean may send two types of notifications: filematch, and state attribute changed.

Definition at line 541 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.FILE_MATCHES_NOTIFICATION.

◆ getRootDirectory()

String com.sun.jmx.examples.scandir.DirectoryScanner.getRootDirectory ( )

Gets the root directory at which this DirectoryScannerMXBean will start scanning the file system.

This is a shortcut to getConfiguration().{getRootDirectory()}.

Returns
This DirectoryScannerMXBean root directory.
Exceptions
IOExceptionA connection problem occurred when accessing the underlying resource.
InstanceNotFoundExceptionThe underlying MBean is not registered in the MBeanServer.

Implements com.sun.jmx.examples.scandir.DirectoryScannerMXBean.

Definition at line 216 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.rootFile.

◆ getState()

ScanState com.sun.jmx.examples.scandir.DirectoryScanner.getState ( )

Get The DirectoryScanner state.

Returns
the current state of the DirectoryScanner.
Exceptions
IOExceptionA connection problem occurred when accessing the underlying resource.
InstanceNotFoundExceptionThe underlying MBean is not registered in the MBeanServer.

Implements com.sun.jmx.examples.scandir.DirectoryScannerMXBean.

Definition at line 222 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.state.

Referenced by com.sun.jmx.examples.scandir.DirectoryScannerTest.testGetState().

Here is the caller graph for this function:

◆ logResult()

boolean com.sun.jmx.examples.scandir.DirectoryScanner.logResult ( File  file,
Action[]  actions 
)
private

◆ notifyMatch()

boolean com.sun.jmx.examples.scandir.DirectoryScanner.notifyMatch ( File  file)
private

◆ removeNotificationListener() [1/2]

void com.sun.jmx.examples.scandir.DirectoryScanner.removeNotificationListener ( NotificationListener  listener) throws ListenerNotFoundException

MBeanNotification support - delegates to broadcaster.

Definition at line 559 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.broadcaster.

◆ removeNotificationListener() [2/2]

void com.sun.jmx.examples.scandir.DirectoryScanner.removeNotificationListener ( NotificationListener  listener,
NotificationFilter  filter,
Object  handback 
) throws ListenerNotFoundException

MBeanNotification support - delegates to broadcaster.

Definition at line 567 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.broadcaster.

◆ scan() [1/2]

void com.sun.jmx.examples.scandir.DirectoryScanner.scan ( )

Scans the file system starting at the specified root directory.

If a file that matches this DirectoryScannerMXBean getConfiguration criteria is found, the DirectoryScannerMXBean takes the {actions} for which it was #getConfiguration configured}: emit a notification, and or log a { com.sun.jmx.examples.scandir.config.ResultRecord} for this file, and or delete that file.

The code that would actually delete the file is commented out - so that nothing valuable is lost if this example is run by mistake on the wrong set of directories.

This method returns only when the directory scan is completed, or if it was stopped by another thread.

Exceptions
IllegalStateExceptionif already ScanState#RUNNING
IOExceptionA connection problem occurred when accessing the underlying resource.
InstanceNotFoundExceptionThe underlying MBean is not registered in the MBeanServer.

Implements com.sun.jmx.examples.scandir.DirectoryScannerMXBean.

Definition at line 243 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.currentTask, com.sun.jmx.examples.scandir.DirectoryScanner.ScanTask.execute(), com.sun.jmx.examples.scandir.DirectoryScanner.rootFile, com.sun.jmx.examples.scandir.DirectoryScanner.setStateAndNotify(), and com.sun.jmx.examples.scandir.DirectoryScanner.state.

Referenced by com.sun.jmx.examples.scandir.DirectoryScanner.ScanTask.scan(), and com.sun.jmx.examples.scandir.DirectoryScannerTest.testGetState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scan() [2/2]

void com.sun.jmx.examples.scandir.DirectoryScanner.scan ( ScanTask  task,
LinkedList< File >  list 
)
private

◆ setStateAndNotify()

final void com.sun.jmx.examples.scandir.DirectoryScanner.setStateAndNotify ( ScanState  desired)
private

◆ stop()

void com.sun.jmx.examples.scandir.DirectoryScanner.stop ( )

Stops the current scan if running. After this method completes the state of the application will be STOPPED.

Exceptions
IOExceptionA connection problem occurred when accessing the underlying resource.
InstanceNotFoundExceptionThe underlying MBean is not registered in the MBeanServer.

Implements com.sun.jmx.examples.scandir.DirectoryScannerMXBean.

Definition at line 210 of file DirectoryScanner.java.

References com.sun.jmx.examples.scandir.DirectoryScanner.setStateAndNotify().

Here is the call graph for this function:

◆ validateRoot()

static File com.sun.jmx.examples.scandir.DirectoryScanner.validateRoot ( String  root)
staticprivate

Definition at line 578 of file DirectoryScanner.java.

Referenced by com.sun.jmx.examples.scandir.DirectoryScanner.DirectoryScanner().

Here is the caller graph for this function:

Member Data Documentation

◆ actions

final Set<Action> com.sun.jmx.examples.scandir.DirectoryScanner.actions
package

◆ broadcaster

final NotificationBroadcasterSupport com.sun.jmx.examples.scandir.DirectoryScanner.broadcaster
private

◆ config

final DirectoryScannerConfig com.sun.jmx.examples.scandir.DirectoryScanner.config
private

◆ currentTask

volatile ScanTask com.sun.jmx.examples.scandir.DirectoryScanner.currentTask = null
private

◆ FILE_MATCHES_NOTIFICATION

final String com.sun.jmx.examples.scandir.DirectoryScanner.FILE_MATCHES_NOTIFICATION
static
Initial value:
=
"com.sun.jmx.examples.scandir.filematch"

The type for com.sun.jmx.examples.scandir.filematch notifications. Notifications of this type will be emitted whenever a file that matches this

criteria is found, but only if this

was configured to {notify} for matching files.

Definition at line 115 of file DirectoryScanner.java.

Referenced by com.sun.jmx.examples.scandir.DirectoryScanner.getNotificationInfo(), and com.sun.jmx.examples.scandir.DirectoryScanner.notifyMatch().

◆ LOG

final Logger com.sun.jmx.examples.scandir.DirectoryScanner.LOG
staticprivate

◆ logManager

final ResultLogManager com.sun.jmx.examples.scandir.DirectoryScanner.logManager
package

◆ rootFile

final File com.sun.jmx.examples.scandir.DirectoryScanner.rootFile
private

◆ state

volatile ScanState com.sun.jmx.examples.scandir.DirectoryScanner.state = STOPPED
private

The documentation for this class was generated from the following file:
com.sun.jmx.examples.scandir.DirectoryScanner.config
final DirectoryScannerConfig config
Definition: DirectoryScanner.java:142
com.sun.jmx.examples.scandir.DirectoryScanner.DirectoryScanner
DirectoryScanner(DirectoryScannerConfig config, ResultLogManager logManager)
Definition: DirectoryScanner.java:178
name
A Simple Chat Server Example the server takes input from a it handles the startup and handles incoming connections on the listening sockets It keeps a list of connected client and provides methods for sending a message to them Client represents a connected it provides methods for reading writing from to the underlying socket It also contains a buffer of input read from the user DataReader provides the interface of the two states a user can be in Waiting for a name(and not receiving any messages while doing so, implemented by NameReader) and waiting for messages from the user(implemented by MessageReader). ClientReader contains the "main loop" for a connected client. NameReader is the initial state for a new client