-
1. Re: JBossCache on JBoss Application Server
brian.stansberry May 17, 2007 10:16 AM (in response to alohamojo)MBeanServerLocator.locateJBoss() only works inside the AS itself, not remotely.
Have a look at Section 13.1 of http://labs.jboss.com/file-access/default/members/jbosscache/freezone/docs/1.4.1/TreeCache/en/html/jboss_integration.html#d0e2757 which will tell you how to bind a proxy to your cache into JNDI. Note the example uses TreeCacheMBean as the interface; you'd use PojoCacheMBean.
You'd then access the cache from the remote client using:Hashtable env = .... configure your naming env or use jndi.properties InitialContext ctx = new InitialContext(env); PojoCacheMBean cache = (PojoCacheMBean) ctx.lookup("MyCache");
-
2. Re: JBossCache on JBoss Application Server
alohamojo May 18, 2007 5:28 AM (in response to alohamojo)Thanks for your reply.
Now i have another problem:
Here is the configuration:<server> <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/> <mbean code="org.jboss.cache.aop.PojoCache" name="jboss.cache:service=PojoCache"> <depends>jboss:service=Naming</depends> <depends>jboss:service=TransactionManager</depends> <attribute name="IsolationLevel">REPEATABLE_READ</attribute> <attribute name="CacheMode">REPL_SYNC</attribute> <attribute name="UseReplQueue">false</attribute> <attribute name="ReplQueueInterval">0</attribute> <attribute name="ReplQueueMaxElements">0</attribute> <attribute name="ClusterName">TreeCache-Cluster</attribute> <attribute name="ClusterConfig"> <config> <UDP mcast_addr="228.1.2.3" mcast_port="48866" bind_addr="192.168.1.12" ip_ttl="64" ip_mcast="true" mcast_send_buf_size="150000" mcast_recv_buf_size="80000" ucast_send_buf_size="150000" ucast_recv_buf_size="80000" loopback="false"/> <PING timeout="2000" num_initial_members="3" up_thread="false" down_thread="false"/> <MERGE2 min_interval="10000" max_interval="20000"/> <FD_SOCK/> <VERIFY_SUSPECT timeout="1500" up_thread="false" down_thread="false"/> <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800" max_xmit_size="8192" up_thread="false" down_thread="false"/> <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10" down_thread="false"/> <pbcast.STABLE desired_avg_gossip="20000" up_thread="false" down_thread="false"/> <FRAG frag_size="8192" down_thread="false" up_thread="false"/> <pbcast.GMS join_timeout="5000" join_retry_timeout="2000" shun="true" print_local_addr="true"/> <pbcast.STATE_TRANSFER up_thread="true" down_thread="true"/> </config> </attribute> <attribute name="FetchInMemoryState">true</attribute> <attribute name="InitialStateRetrievalTimeout">15000</attribute> <attribute name="SyncReplTimeout">15000</attribute> <attribute name="LockAcquisitionTimeout">10000</attribute> <attribute name="EvictionPolicyClass"></attribute> <attribute name="UseRegionBasedMarshalling">true</attribute> </mbean> <mbean code="org.jboss.invocation.jrmp.server.JRMPProxyFactory" name="jboss.jmx:service=proxyFactory,type=jrmp,target=factory"> <attribute name="InvokerName">jboss:service=invoker,type=jrmp</attribute> <attribute name="TargetName">jboss.cache:service=PojoCache</attribute> <attribute name="JndiName">MyCache</attribute> <attribute name="InvokeTargetMethod">true</attribute> <attribute name="ExportedInterface">org.jboss.cache.aop.PojoCacheMBean</attribute> <attribute name="ClientInterceptors"> <iterceptors> <interceptor>org.jboss.proxy.ClientMethodInterceptor</interceptor> <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor> <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor> </iterceptors> </attribute> <depends>jboss:service=invoker,type=jrmp</depends> <depends>jboss.cache:service=PojoCache</depends> </mbean> </server>
And here is an object i want to put in cache:@org.jboss.cache.aop.annotation.InstanceOfPojoCacheable public class Person { protected String name; protected Address address; public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setAddress(Address address) { this.address = address; } public Address getAddress() { return this.address; }
When i try to put object to cache like this:Context jndiContext = new InitialContext(); PojoCacheMBean cache = (PojoCacheMBean) jndiContext.lookup("MyCache"); Person p = new Person(); p.setName("p"); cache.putObject("/a/b/c", p);
below error reported:[java] java.lang.reflect.UndeclaredThrowableException [java] at $Proxy0.putObject(Unknown Source) [java] at test.examples.TestAS.main(TestAS.java:21) [java] Caused by: java.rmi.MarshalException: error marshalling arguments; nested exception is: [java] java.io.NotSerializableException: examples.Person [java] at sun.rmi.server.UnicastRef.invoke(Unknown Source) [java] at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source) [java] at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:133) [java] at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInterceptor.java:365) [java] at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:197) [java] at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:70) [java] at org.jboss.proxy.ClientMethodInterceptor.invoke(ClientMethodInterceptor.java:74) [java] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:100) [java] ... 2 more [java] Caused by: java.io.NotSerializableException: examples.Person [java] at java.io.ObjectOutputStream.writeObject0(Unknown Source) [java] at java.io.ObjectOutputStream.writeArray(Unknown Source) [java] at java.io.ObjectOutputStream.writeObject0(Unknown Source) [java] at java.io.ObjectOutputStream.writeObject(Unknown Source) [java] at org.jboss.invocation.MarshalledValue.<init>(MarshalledValue.java:70) [java] at org.jboss.invocation.MarshalledInvocation.createMarshalledValue(MarshalledInvocation.java:632) [java] at org.jboss.invocation.MarshalledInvocation.writeExternal(MarshalledInvocation.java:570) [java] at java.io.ObjectOutputStream.writeExternalData(Unknown Source) [java] at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source) [java] at java.io.ObjectOutputStream.writeObject0(Unknown Source) [java] at java.io.ObjectOutputStream.writeObject(Unknown Source) [java] at sun.rmi.server.UnicastRef.marshalValue(Unknown Source) [java] ... 10 more
Please let me know what's wrong with my configuration.
Thanks -
3. Re: JBossCache on JBoss Application Server
brian.stansberry May 18, 2007 10:35 AM (in response to alohamojo)You're trying to communicate with a cache in a remote VM. All the business with binding a proxy to the cache in JNDI and then looking up the proxy on the client side just gives your client an object to invoke on that implements the PojoCacheMBean interface and that will make remote calls back to the server. But the putObject() is still a remote call -- any object you pass has to be serialized for the remote call and thus has to implement Serializable.
If you want PojoCache to handle this for you, you need to instantiate an instance of the cache on the client side, and have it cluster with the one on the server side. You can then call putObject() against a real cache, rather than a proxy.