Java Reference
In-Depth Information
private void revaluateDirectories() {
File src = new File(srcDir);
File dest = new File(destDir);
if (!src.exists())
src.mkdirs();
if (!dest.exists())
dest.mkdirs();
}
}
Now you can configure one or more file replicator instances in the bean configuration file for your
needs (in the example, this file is called beans-jmx.xml ). The documentReplicator instance needs
references to two directories: a source directory from which files are read and a target directory to which
files are backed up. The code in this example attempts to read from a directory called docs in your
operating system user's home directory and then copy to a folder called docs_backup in your operating
system user's home directory. When this bean starts up, it creates the two directories if they don't
already exist there.
Tip The “home directory” is different for each operating system, but typically on Unix it's the directory that
~ resolves to. On a Linux box, the folder might be /home/user. On Mac OS X, the folder might be /Users/user ,
and on Windows it might similar to C:\Documents and Settings\user .
<beans xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">
<bean id="fileCopier"
class="com.apress.springenterpriserecipes.replicator.FileJMXCopierImpl" />
<bean id="documentReplicator"
class="com.apress.springenterpriserecipes.replicator.
FileJMXcReplicatorImpl">
<property name="srcDir" value="#{systemProperties['user.home']}/docs" />
<property name="destDir" value="#{systemProperties['user.home']}
/docs_backup" />
<property name="fileCopier" ref="fileCopier" />
</bean>
</beans>
Registering MBeans Without Spring's Support
First, let's see how to register a model MBean using the JMX API directly. In the following Main class, you
get the documentReplicator bean from the IoC container and register it as an MBean for management
and monitoring. All properties and methods are included in the MBean's management interface.
package com.apress.springenterpriserecipes.replicator;
...
import java.lang.management.ManagementFactory;
Search WWH ::




Custom Search