EJB 3.1 singleton in cluster - singleton

I didn't find much information about EJB 3.1 Singletons in cluster enviroment.
Is it true that specification says that those singletons will guarantee one instance per JVM - so one per cluster node. Not one per whole cluster?

Yes, section 4.8 of the EJB 3.1 specification states that "each application will have one bean instance of the Singleton for each JVM".

The singleton itself does not guarantee one instance per cluster. For that you need to specify a dependency. If you are using jboss then it is "jboss.ha:service=HASingletonDeployer,type=Barrier".

Related

Scheduling in jboss7 (and in wildfly) without using EJB

I want to use scheduling in jboss7 (and in wildfly) but I don't want to use any EJB. I know the EJB #Schedule can be used but I have a web application and the same WAR should be used in Tomcat too so EJB is out of the question.
What can I use for scheduling?
Thanks,
V.

Deploy Java EE application without starting

I am using Apache Geronimo. I need a way to deploy an EAR application on an application server without starting the EAR module automatically.
When I deploy my EAR, it is automatically started. I need a way to specify, that it should only be deployed but not started.
Is there a way to do this?
In the past I've opened and closed gates to certain EJBs with the use of JMX.
The cool part:
100% Control your beans from outside using JConsole or your own JMX client.
The drawback:
Every bean instance has to be registered in the MBean Server which is not that cool as you are usually having multiple instances of the same bean.
The solution to this topic was having a #Singleton EJB working as a MBean/controller for all the instances of one EJB.

Glassfish, EJB Load balancing

I'm having a problem with ejb load balancing inside glassfish 3 cluster.
I have one ear project witch contains EJB module and WEB module. All my EJB's are stateless and remote in EJB module. In WEB module I have one servlet which suppose to lookup for ejb and print on which instance in cluster he get ejb.
I'm calling EJB from servlet like this:
Properties props = System.getProperties();
props.setProperty("com.sun.appserv.iiop.endpoints", "10.8.10.202:23700,10.8.10.203:23700,10.8.10.204:23700,10.8.10.205:23700");
InitialContext ic = new InitialContext();
EJBRemote ejb = (EJBRemote) ic.lookup("java:global/app-name-ear/app-ejbs/EJB!com.tt.EJBRemote");
Problem is that my request always ends up on first instance of 4 possible.
How I can achieve load balancing in my case? Do I need stand alone client (web-app in separate project)? How glassfish cluster knows that there are another instances where my servlet can lookup for EJB?
Your issue is that you don't have enough load. and the way you look up EJBs is odd.
To look up remote EJB, rather than the properties in a servlet. but the CORBA / IIOP URL in the JNDI resources of the server. (in the admin console)
When you load balance, with IIOP each lookup binds to one instance and only switches to another instance for failover.
essentially you don't have enough load on the system to trigger the other instances of the EJB. Perhaps reduce the pool size to one to simulate high load.

Is there a way to configure MDBs programatically?

I am currently working on a EJB 3.1 based project running on GlassFish that uses a custom built framework to configure the functionality of any SessionBeans. Using this we can enable, disable and re-configure most of the services at run-time. Unfortunately we can't extend this to support conifguration of MDBs. I would like to set the selector a MDB is using based upon the configuration information and re-configure this if the settings change.
Unfortunately I could only come up with a SessionBean that creates MessageConsumers natively on the JMS Sessions based upon the configuration and to have the JMS messages handleb by MessageListeners, but I was told this way we would be loosing concurrency and the transaction handling of the EJB system, as we would no longer be using MDBs this way.
So is there any way to do what I'm looking for using MDBs? Someone told me there are some planned extensions in new EJB and JMS spec drafts, but I couln't find a pointer to that particular topic.
No, MDBs are configured by the Deployer at deploy-time.
Similar question answered here: Configuring MappedName annotation in Message Driven Bean dynamically

Lookup a Message Driven Bean via JNDI

If I create a MessageDriven bean - is it available to other components in my app via JNDI? If so, how can I find/specify the name to look it up by? I'm deploying to glassfish if that makes any difference?
Assigning a JNDI name for an MDB is not required by Java EE specification (chapter 21.2.3 of EJB 3.0):
At the minimum, the EJB container must provide a JNDI API name space to the enterprise bean
instances. The EJB container must make the name space available to an instance when the instance invokes the javax.naming.InitialContext default (no-arg) constructor.
The business interfaces of other enterprise beans
[...]
MDBs don't qualify, as they don't have a business interface. Besides, since wiring up an MDB in another EJB/MDB would have little sense (what's your use case, BTW?), is probably skipped in Glassfish.
I've seen that WebLogic, for example allows that in its proprietary deployment descriptor, but I've never used it.