jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edgarp...@apache.org
Subject svn commit: r415419 - in /jackrabbit/trunk/jcr-rmi: ./ src/java/org/apache/jackrabbit/rmi/server/jmx/ src/resources/
Date Mon, 19 Jun 2006 21:03:10 GMT
Author: edgarpoce
Date: Mon Jun 19 14:03:09 2006
New Revision: 415419

URL: http://svn.apache.org/viewvc?rev=415419&view=rev
Log:
JCR-459 Add JMX support to register a JCR RMI Server into Jboss

Added:
    jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/
    jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java
    jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java
    jackrabbit/trunk/jcr-rmi/src/resources/
    jackrabbit/trunk/jcr-rmi/src/resources/jackrabbit-rmi-service.xml
Modified:
    jackrabbit/trunk/jcr-rmi/project.xml

Modified: jackrabbit/trunk/jcr-rmi/project.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jcr-rmi/project.xml?rev=415419&r1=415418&r2=415419&view=diff
==============================================================================
--- jackrabbit/trunk/jcr-rmi/project.xml (original)
+++ jackrabbit/trunk/jcr-rmi/project.xml Mon Jun 19 14:03:09 2006
@@ -89,6 +89,13 @@
           <include>README.txt</include>
         </includes>
       </resource>
+      <resource>
+        <targetPath>.</targetPath>
+        <directory>src/resources</directory>
+        <includes>
+          <include>*</include>
+        </includes>
+      </resource>
     </resources>
     <unitTest>
       <includes>

Added: jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java?rev=415419&view=auto
==============================================================================
--- jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java
(added)
+++ jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java
Mon Jun 19 14:03:09 2006
@@ -0,0 +1,133 @@
+package org.apache.jackrabbit.rmi.server.jmx;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.jcr.Repository;
+import javax.naming.InitialContext;
+
+import org.apache.jackrabbit.rmi.remote.RemoteRepository;
+import org.apache.jackrabbit.rmi.server.RemoteAdapterFactory;
+import org.apache.jackrabbit.rmi.server.ServerAdapterFactory;
+
+/**
+ * MBean that registers a JCR RMI server through JNDI.
+ */
+public class JCRServer implements JCRServerMBean {
+
+    /**
+     * local repository address
+     */
+    private String localAddress;
+
+    /**
+     * remote repository address
+     */
+    private String remoteAddress;
+
+    /**
+     * Optional local JNDI environment properties
+     */
+    private String localEnvironment;
+
+    /**
+     * Optional remote JNDI environment properties
+     */
+    private String remoteEnvironment;
+
+    /**
+     * Remote repository instance
+     */
+    RemoteRepository remote;
+
+    public void start() throws Exception {
+
+        if (this.localAddress == null) {
+            throw new IllegalStateException("local repository address is null");
+        }
+
+        if (this.remoteAddress == null) {
+            throw new IllegalStateException("remote repository address is null");
+        }
+
+        // local repository
+        InitialContext localContext = createInitialContext(localEnvironment);
+        Repository localRepository = (Repository) localContext
+                .lookup(this.localAddress);
+        if (localRepository == null) {
+            throw new IllegalArgumentException("local repository not found at "
+                    + this.localAddress);
+        }
+
+        // remote repository
+        InitialContext remoteContext = createInitialContext(remoteEnvironment);
+        RemoteAdapterFactory factory = new ServerAdapterFactory();
+        remote = factory.getRemoteRepository(localRepository);
+
+        // bind remote server
+        remoteContext.bind(this.remoteAddress, remote);
+    }
+
+    /**
+     * 
+     * @param jndiProps
+     *            jndi environment properties
+     * @return an InitialContext for the given environment properties
+     * @throws Exception
+     *             if any error occurs
+     */
+    private InitialContext createInitialContext(String jndiProps)
+            throws Exception {
+        InitialContext initialContext = null;
+        if (jndiProps != null) {
+            InputStream is = new ByteArrayInputStream(jndiProps.getBytes());
+            Properties props = new Properties();
+            props.load(is);
+            initialContext = new InitialContext(props);
+        } else {
+            initialContext = new InitialContext();
+        }
+        return initialContext;
+    }
+
+    public void stop() throws Exception {
+        // unbind remote server
+        InitialContext ctx = new InitialContext();
+        ctx.unbind(this.remoteAddress);
+        remote = null;
+    }
+
+    public String getLocalAddress() {
+        return localAddress;
+    }
+
+    public void setLocalAddress(String localAddress) {
+        this.localAddress = localAddress;
+    }
+
+    public String getRemoteAddress() {
+        return remoteAddress;
+    }
+
+    public void setRemoteAddress(String remoteAddress) {
+        this.remoteAddress = remoteAddress;
+    }
+
+    public String getLocalEnvironment() {
+        return localEnvironment;
+    }
+
+    public void setLocalEnvironment(String localEnvironment) {
+        this.localEnvironment = localEnvironment;
+    }
+
+    public String getRemoteEnvironment() {
+        return remoteEnvironment;
+    }
+
+    public void setRemoteEnvironment(String remoteEnvironment) {
+        this.remoteEnvironment = remoteEnvironment;
+    }
+
+}

Added: jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java?rev=415419&view=auto
==============================================================================
--- jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java
(added)
+++ jackrabbit/trunk/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java
Mon Jun 19 14:03:09 2006
@@ -0,0 +1,25 @@
+package org.apache.jackrabbit.rmi.server.jmx;
+
+public interface JCRServerMBean {
+
+    public void start() throws Exception;
+
+    public void stop() throws Exception;
+
+    public String getLocalAddress();
+
+    public void setLocalAddress(String address);
+
+    public String getRemoteAddress();
+
+    public void setRemoteAddress(String address);
+
+    public String getRemoteEnvironment();
+
+    public void setRemoteEnvironment(String remoteEnvironment);
+
+    public String getLocalEnvironment();
+
+    public void setLocalEnvironment(String localEnvironment);
+
+}

Added: jackrabbit/trunk/jcr-rmi/src/resources/jackrabbit-rmi-service.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jcr-rmi/src/resources/jackrabbit-rmi-service.xml?rev=415419&view=auto
==============================================================================
--- jackrabbit/trunk/jcr-rmi/src/resources/jackrabbit-rmi-service.xml (added)
+++ jackrabbit/trunk/jcr-rmi/src/resources/jackrabbit-rmi-service.xml Mon Jun 19 14:03:09
2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+	<mbean code="org.apache.jackrabbit.rmi.server.jmx.JCRServer"
+		name="Jackrabbit.services:RMIServer = JCR RMI Server">
+		<attribute name="LocalAddress">java:jcr/local</attribute>
+		<attribute name="RemoteAddress">jnp://localhost:1099/jcrServer</attribute>

+		<!-- Optional attribute 
+		<attribute name="LocalEnvironment">
+			java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+			java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
+			java.naming.provider.url=localhost:1099
+		</attribute>	
+		 -->
+		<!-- Optional attribute
+		<attribute name="RemoteEnvironment">
+			java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+			java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
+			java.naming.provider.url=localhost:1099
+		</attribute>	
+		-->
+		<depends>jboss.jca:service=ManagedConnectionFactory,name=jcr/local</depends>
				
+	</mbean>
+</server>



Mime
View raw message