Accessing data between jar files with two different processes - java

I have 4 applications in running websphere application server,one as ear file and other 3 based on message driven beansas jar files . Now i am trying to add one more application i.e jar file this application will start up on server and keep all the data in hashmap object. i want to read this hashmap object using 4th application api through one of the message driven bean code.
Is it possible to read 4th application hashmap object without RMI call?

It sounds like you want some sort of singleton service which will be utilized by the other apps on the app server. You can implement this as a #Singleton ejb, which can then be accessed by other apps using standard ejb invocation methods.

Related

I have 2 .ear file inside a single domain (abc.ear and def.ear). How can I communicate between them

I have 2 .ear file under a single domain (eg : abc.ear, def.ear). How to communicate between them?
You can use Remote Method Invocation. Usually the beans of your application will be registered in the application server upon deployment. With the correct name you can then use a lookup to get that remote bean (remote meaning a bean from the other .ear). From there on you an use that bean as if it was a local one.
I am sure you can find a good tutorial on RMI for your specific application server.
EDIT: I just noticed that communicate is a rather broad term and my interpretation might not fit what you want. RMI is used to call methods and objects. If communicate means to transfer data only you could also use a middleware like Java Message Service to send messages to the other .ear.

Execute Command from Web Archive

I included a scheduled job in my WAR file through Quartz and Spring. In case that the scheduled job misses, I have to execute a method Class_A.Method_A() explicitly.
In order to execute the method, I plan to create a static method main() under Class_A so that I can execute jar -cp $CLASSPATH Class_A. However, the class is inside the WAR file, how can I do it?
In addition, the WAR file has its data source and log4j configuration and the method Method_A does database access and logging through them, if I call it on command prompt, is there any conflict?
If calling it through a comamnd prompt is not a good practice, what is a better way? Please help.
Why are you trying to execute 'jar -cp'. This will be a separate jvm execution and hence you will not be able to directly access the resources in the jvm running the web application (this means objects spawned in the jvm's memory space by the web application). [This is answer to your question about conflict/
Please mention what application server on which your web application is running.
Seeing your comment about System Administrator (though I would have mentioned this regardless of this as well). Have you ever heard of ServiceMBeans, you can try them.
Your scenario is a very generalized scenario, where people need to access a particular class (better say instance of the class) running inside a JVM. You certainly need something which loads up along with the application.
You can write a Service MBean to run along (inside) your web application. This would mean you are exposing action. Then you can write a java client to interact with the MBean and make call to its exposed methods.
In case your application server provides authentication for accessing MBeans.
Other option is JMS implementation. Setup a JMSQueue, whose listener will execute the action interacting with the classes of web application. Obviously the listener would load along side web application. EJB implementation would allow you to load the listener via simple ejb xml or through annotations.
Then you write up a separate java code which can send message commands to the JMSQueue.
All application server provides the option of authentication.

Create and start a thread of a Java web service operation

Can i create and start a thread from inside a web service operation of a Java Web Application normally?If yes should that thread class be in the classes of the Web Application or the Java Application that consumes the service?
The server JVM will certainly need to load the classes used by your new thread, so they will need to be somewhere on the server classpath. Unless you also need to use some or all of them on the client application there will be no need for them to be on the client classpath. How you name and package them is up to you but if they are only used inside the server app it would make sense to use similar names or the same parent packages.
You should consider using something like Quartz to manage your threads and depending on what you want this web service to do, consider using JMS/MDB instead.

weblogic java parameters

I have a web service which access 2 other web services. I need to deploy this web service but some how I need to change the urls from the others web wervices, later.
My question is, how can I do to pass parameters to a web service at any time. Maybe a config file, or something. In .net we have web.config, do we have this in java?
kind regards,
José Cruz
Java uses property files for runtime configuration to allow for changes after deployment. Basically it's a text file with a list of key value pairs that Java can read easily and put into a HashMap which can be accessed by the user.
http://www.exampledepot.com/egs/java.util/Props.html

BlazeDS and Java class in WAR file

Hi I have a java class which has been deployed as WAR web application in a BlazeDS/Spring server sitting on JBOSS.
Apart from the Flex application which will access the WAR file, I also need to start some server side process's which will initiate BlazeDS "pushes" to the Flex client via AMF messaging.
What is the best way to implement this server side process?
- Should it just be a class with a main() method in the WAR file which gets called from the command line? Can this be done - not sure you can run a class in a WAR file from command line?
- Should it just be a class with a main() method in a JAR file which gets called from the command line?
Not sure what the standard practise here is. The key is that the process needs to be started on the BlazeDS server to push data out (not on the Flex client).
Any help would he appreacited
Mike
First off, are you using the latest Spring/BlazeDS integration? If not, I highly recommend checking it out here. It can greatly simplify setting up message destinations for push messaging. It also will allow you to use JMS and Spring Integration message destinations as well as integrate Spring Security if you so choose.
Now to answer your question. What are the life-cycle requirements for your data push service? Do you want to be able to control the parameters of this data push (i.e., starting and stopping it, frequency, etc.) from other classes? Creating this service using Spring will allow you to inject it into other beans for control as you so desire.
I currently have a similar use case in which I use a BlazeDS message destination to "push" telemetry data to a client browser. I setup a "service" class that is instantiated by Spring as a singleton instance.
If you do not need external control of this singleton, I then suggest you use an annotated #PostConstruct or "init" method for creating a Thread and starting it with an anonymous Runnable representing your main loop. If your service needs to push data at a predefined frequency, you might consider a java.util.concurrent.ScheduledExecutorService.
Either way, you will also need to setup an annotated #PreDestory or "destroy" method that will execute just before the singleton instance is destroyed. This will allow you to insert code to safely stop the loop Thread or ScheduledFuture and clean up any necessary resources before the Spring container is shut down.
If you want further interaction with your service, you can manipulate it from other classes (such as Web controllers, etc.) using a service interface. Have your class implement this interface and inject your class into other classes using this interface. For a more daring solution, you might consider using dm Server or another OSGi container and create an OSGi service.
Please let me know if you need further help regarding this process or if there are specific details that I can illuminate further.
Marshall your a star - thanks for that!
I am using the Spring #PostConstruct and this is working a treat. It appears that the Monitoring class is getting instantiated by Spring automatically and then the #PostConstruct method is being called.
I also had to include the following in the Spring config file to get this to work:
xmlns:context=springframework.org/schema/context
springframework.org/schema/context
springframework.org/schema/context/spring-context-2.5.xsd
Within the #PostConstruct method I have implemented a simple java.util.Timer which pushes data to the Flex client are regular intervals. (I still need to set it up as a singleton via Spring - im a bit of Spring newbie!)
Does the ScheduledExecutorService offer any benefits above the Timer class for my purposes?
Once again thanks
Regards
Michael

Categories