[JNDI and Naming] - EJB 3.1 @Singleton remote access
by Christian Tre
Christian Tre [http://community.jboss.org/people/RET] created the discussion
"EJB 3.1 @Singleton remote access"
To view the discussion, visit: http://community.jboss.org/message/542570#542570
--------------------------------------------------------------
Hello!
While testing the new @Singleton-Annotation almost completely implemented in JBoss AS 6 M3 i encountered several problems during deploying or getting the right Interface.
My Remote Interface:
@Remote
@RemoteBinding(jndiBinding=ParameterHolder.JNDI_BINDING)
public interface ParameterHolder {
public static final String JNDI_BINDING = JNDI_PREFIX + "core/ParameterHolder";
public abstract void reloadAll();
/**
* Methode für Interceptoren, um bestimmte Parameter
* nach einem Create / Update / Delete neu zu laden
* @param oid
*/
public abstract void reload(Parameter param);
public abstract void unload(Parameter param);
public abstract Parameter get(String name, Company company);
}
my Local Interface:
@Local
@LocalBinding(jndiBinding=ParameterHolderLocal.JNDI_BINDING)
public interface ParameterHolderLocal {
public static final String JNDI_BINDING = ParameterHolder.JNDI_BINDING + JNDI_SUFFIX_LOCAL;
public abstract void reloadAll();
/**
* Methode für Interceptoren, um bestimmte Parameter
* nach einem Create / Update / Delete neu zu laden
* @param oid
*/
public abstract void reload(Parameter param);
public abstract void unload(Parameter param);
public abstract Parameter get(String name, Company company);
}
my BeanImplementation:
@Singleton
@Startup
@DependsOn(ParameterServiceLocal.JNDI_BINDING)
public class ParameterHolderImpl implements ParameterHolder, ParameterHolderLocal {
private static Set<Parameter> params = new HashSet<Parameter>();
private Log LOG = LogFactory.getLog(this.getClass());
@EJB(mappedName=ParameterServiceLocal.JNDI_BINDING)
private ParameterServiceLocal parameterservice;
@PostConstruct
private void init() {
params.clear();
params.addAll(parameterservice.findAll());
}
@SuppressWarnings("unused")
@PreDestroy
private void destroy() {
params.clear();
}
@Lock(LockType.WRITE)
public void reloadAll() {
init();
}
/**
* Methode für Interceptoren, um bestimmte Parameter
* nach einem Create / Update / Delete neu zu laden
* @param oid
*/
@Lock(LockType.WRITE)
public void reload(Parameter param) {
if (param == null) {
return;
}
if (LOG.isTraceEnabled()) {
LOG.trace("reload \"" + param.getName() + "\" from Company " + param.getCompany());
}
// da es sein kann, dass der Parameter neu erstellt wurde, muss er nochmal nachgeladen werden
param = parameterservice.findByName(param.getName(), param.getCompany());
// wenn der param nicht null ist und entweder nicht in der Liste ist (also neu angelegt)
// oder in der Liste ist und gelöscht werden konnte
if (param != null && (!params.contains(param) || params.remove(param))) {
params.add(param);
} else {
if (LOG.isWarnEnabled()) {
LOG.warn("cannot reload Parameter: " + param);
}
}
}
@Lock(LockType.WRITE)
public void unload(Parameter param) {
if (param == null) {
return;
}
if (LOG.isTraceEnabled()) {
LOG.trace("unload \"" + param.getName() + "\" from Company " + param.getCompany());
}
params.remove(param);
}
@Lock(LockType.READ)
public Parameter get(String name, Company company) {
Iterator<Parameter> iter = params.iterator();
while (iter.hasNext()) {
Parameter p = iter.next();
if (p.getCompany().equals(company) && p.getName().equals(name)) {
return p;
}
}
return null;
}
}
At my ParameterServiceImpl i added Interceptors to the write / update / delete-Methods to renew these one Parameter in the global Cache (this Singleton)
in my serverlog this line appeared on deploying my app:
2010-05-12 13:12:08,040 WARN [org.jboss.ejb3.session.SessionContainer] (HDScanner) No JndiSessionRegistrarBase was found; byassing binding of Proxies to jboss.j2ee:service=EJB3,name=ParameterHolderImpl in Global JNDI.
(yes, its byassing instead of bypassing ;) )
in my junittest
public class CoreServicesRemoteTest extends TestCase {
private Context ctx;
private CompanyService cs;
private ParameterService ps;
private ParameterHolder ph;
protected void setUp() throws Exception {
super.setUp();
ctx = new JndiConnection().getInitialContext();
assertNotNull(ctx);
cs = (CompanyService) ctx.lookup(CompanyService.JNDI_BINDING);
assertNotNull(cs);
ps = (ParameterService) ctx.lookup(ParameterService.JNDI_BINDING);
assertNotNull(ps);
ph = (ParameterHolder) ctx.lookup(ParameterHolder.JNDI_BINDING);
assertNotNull(ph);
}
public void testCompanyCreate() throws Exception {
Company c = cs.create(1, "my Company");
assertNotNull(c);
Parameter p = ps.create("mein Param","Wert", c);
assertNotNull(ps.find(p.getOid()));
assertNotNull(ph.get("mein Param", c));
assertTrue(ps.delete(p));
assertNull(ph.get("mein param", c));
assertTrue(cs.delete(c));
}
}
i get an Communication-Exception at the lookup for Parameterholder:
javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.ejb3.singleton.proxy.impl.invocationhandler.SingletonBeanRemoteInvocationHandler (no security manager: RMI class loader disabled)]
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:847)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)
at javax.naming.InitialContext.lookup(Unknown Source)
at de.neutrasoft.portal.test.CoreServicesRemoteTest.setUp(CoreServicesRemoteTest.java:28)
at junit.framework.TestCase.runBare(TestCase.java:128)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.jboss.ejb3.singleton.proxy.impl.invocationhandler.SingletonBeanRemoteInvocationHandler (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:771)
... 16 more
my second try: make ParameterHolder stateless and with static HashMap, but that fails too, i guess because the Bean is destroyed between 1st Instance + Parameter stuffed and first get-Call on the Map.
Whats the Problem here? Any Classes still missing in M3?
regards, Chris
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/542570#542570]
Start a new discussion in JNDI and Naming at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 11 months
[EJB 3.0] - TimerService configuration with ejb-jar.xml
by Slava Schmidt
Slava Schmidt [http://community.jboss.org/people/slava_schmidt] created the discussion
"TimerService configuration with ejb-jar.xml"
To view the discussion, visit: http://community.jboss.org/message/542560#542560
--------------------------------------------------------------
Hello,
could anyone help me to figure out, how to configure the TimerService in EJB3 using ejb-jar.xml?
Now i use following annotation:
{code}@Resource private TimerService timerService{code}
and it works just fine. But i need to replace all annotations with an xml configuration. So i have tried this (in nearly all possible combinations):
{code:xml}
<resource-ref>
<res-ref-name>EJBTimerService</res-ref-name>
<res-type>javax.ejb.TimerService</res-type>
<mapped-name>EJBTimerService</mapped-name>
<injection-target>
<injection-target-class>com.gkses.muc.master.beans.AbstractTimerControl</injection-target-class>
<injection-target-name>timerService</injection-target-name>
</injection-target>
</resource-ref>
{code:xml}
Naturally, this is wrong. I would very appreciate any help!
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/542560#542560]
Start a new discussion in EJB 3.0 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 11 months
Re: [jboss-user] [JBoss Microcontainer Development] - JBoss Reflect Performance Javassist vs Introspection
by Kabir Khan
Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion
"JBoss Reflect Performance Javassist vs Introspection"
To view the discussion, visit: http://community.jboss.org/message/542552#542552
--------------------------------------------------------------
> Kabir Khan wrote:
>
> I have done some performance measurements where I compare the times taken creating the following class, using javassist.bytecode.* and asm
>
>
> *public* *class* JavassistMethod1 *implements* JavassistMethod
> {
> *public* Object invoke(Object target, Object[] args) *throws* Throwable
> {
> *return* Integer.valueOf(((SomeClass)target).someMethod(((Integer)args[0]).intValue(), (String)args[1])).intValue();
> }
> }
>
>
>
>
>
>
> Which would be used to call the method:
>
> *int* someMethod(*int* i, String);
>
>
>
>
>
>
> The basic flow for what I do for both approaches is the same, whereby I do the following lots of times to generate lots of similar classes:
>
>
>
>
>
> A) - Create class structure
>
> B) - Add default constructor with body to call super
>
> C) - Add invoke method
>
> C1) - Add invoke method body
>
> D) - Convert class structure from A) into byte[]
>
> E) - Define java.lang.Class by calling ClassLoader.defineClass()
>
> F) - Call Class.newInstance()
Chiba has done some great work on creating a new API for Javassist tailor made to create new classes. Taking the defining of the class and instantiating it out of the equation (since that is JVM stuff out of our control), so we do A-D so we have the bytes ready to create the class the times are now for creating 20000 JavassistMethod implementations
|| *ASM* || *Javassist ClassFile* || JavassistClassFileWriter ||
| 476 | 1030 | 356 |
| 613 | 1056 | 269 |
| 483 | 1076 | 309 |
| 464 | 1001 | 357 |
| 383 | 1186 | 315 |
I have attached the modified benchmark
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/542552#542552]
Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 11 months