[JBoss Cache: Core Edition] - Re: JPA entity caching with JBossCache in JBoss-5.0 GA
by bstansberry@jboss.com
"jaikiran" wrote : I'm trying to move a EJB3 JPA example which has second level cache enabled to JBossAS-5.0 GA. I am following this wiki for instructions http://www.jboss.org/community/docs/DOC-13200. Based on those instructions i have been able to get the example deploying successfully in JBoss-5 GA. I have a couple of related questions:
|
|
| 1) Is there a way to access this second level cache from within the application (ex: from a EJB3 bean). I see that the java:CacheManager is registered in the JNDI. So would the following be the correct thing to do:
|
| | private Cache getCache() throws Exception
| | {
| | org.jboss.cache.CacheManager cacheManager = (CacheManager) new InitialContext().lookup("java:CacheManager");
| | return cacheManager.getCache("mvcc-entity", false);
| | }
| |
|
| The org.jboss.cache.CacheManager.getCache() accepts 2 arguments. I could not find the javadocs and wasn't sure what to pass. Based on some explanation from the wiki, i decided to pass mvcc-entity as the first param. What exactly are these parameters used for?
|
Javadocs are at http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs.... The second param is whether the cache manager should create the "mvcc-entity" cache if not already created. Whether you pass true or false depends on whether you want a guaranteed non-null return.
Note that any code that calls getCache() should also call releaseCache() when it is done with the cache. The CacheManager uses reference counting to know when to stop the cache.
anonymous wrote :
| 2) Once i get hold of the cache, is there some way through which i can figure out whether a particular entity is cached?
|
| public boolean isCustomerInCache(Long id){
| |
| | Cache cache = getCache();
| | // is there some way through which i can check if the entity is cached?
| |
| |
| | }
|
|
IMO doing any of this is a bad idea; the cache is an internal structure of the Hibernate SessionFactory. For sure it's a bad idea to document such a thing in any of the EJB3 examples!! :-) If you want to poke around for your own knowledge, the eviction chapter in the Hibernate/JBC guide at http://www.jboss.org/servlet/JiveServlet/download/10386-69-6042/hibernate... includes discussion of how things are stored.
Hibernate provides an API (Statistics) for inspecting the Second Level Cache. See http://www.hibernate.org/hib_docs/v3/reference/en-US/html/performance-ses.... Users should restrict themselves to that API. If an existing EJB3 example pokes around in the cache internals, I encourage you to convert it to use the Hibernate Statistics API.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4199126#4199126
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4199126
15 years, 12 months
[EJB 3.0] - map atrribute
by DanielFT
Hello.
i`m trying to map a attribute that is a Map using jpa annotation.
With hibernate i map like this:
| <class name="User" table="user">
| ...
| <map name="rights" table="user_rights" lazy="false" cascade="all" order-by="entity_id asc" >
| <key column="user_id"/>
| <index column="entity_id" type="string"/>
| <element column="rights" type="string"/>
| </map>
| ....
| </class>
|
it work!. but now i want use jpa annotations.
how can i do it?
i try it:
| @Entity
| public class User implements Serializable {
| ...
| @JoinTable(name = "user_rights",
| joinColumns = { @JoinColumn(name = "user_id") } )
| @MapKey(name="entity_id")
| private Map<String, String> rights;
| ...
|
but it not work
thanks!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4199118#4199118
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4199118
15 years, 12 months
[EJB 3.0] - Re: EJBException: Failed to acquire the pool semaphore, stri
by pbaker01
That did not solve the problem :(
The console log (below) outputs a line each time a message is received and processed. So 20 messages had been started and of those 5 had been completed.
Thanks for replying on New Years day!!! Any other suggestions will be appreciated.
Happy New Year! PB
new MDB:
package com.xxxx.wab.mdb.ssim;
|
| import java.util.ArrayList;
|
| import javax.ejb.ActivationConfigProperty;
| import javax.ejb.MessageDriven;
| import javax.jms.JMSException;
| import javax.jms.Message;
| import javax.jms.MessageListener;
| import javax.jms.ObjectMessage;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| import com.xxxx.wab.dao.MasterFlightDAO;
| import com.xxxx.wab.dao.SubscriberDAO;
| import com.xxxx.wab.dto.SsimRsp;
| import com.xxxx.wab.service.SsimService;
| import com.xxxx.wab.ssim.SsimFlight;
|
| @MessageDriven(mappedName = "jms/SSMListener", activationConfig = {
| @ActivationConfigProperty(propertyName="messagingType", propertyValue="javax.jms.MessageListener"),
| @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "AUTO_ACKNOWLEDGE"),
| @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
| @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "25"),
| @ActivationConfigProperty(propertyName="destination",propertyValue="queue/SSMQueue") })
|
| public class SSMListener implements MessageListener {
|
| @PersistenceContext(unitName="WABPU")
| private EntityManager em;
| SsimService ssimService;
|
| private SsimService getSsimService() {
| if (ssimService == null)
| ssimService = new SsimService(em, null);
| MasterFlightDAO fltDAO = new MasterFlightDAO(em);
| SubscriberDAO subscriberDAO = new SubscriberDAO(em);
| ssimService.setFltDAO(fltDAO);
| ssimService.setSubscriberDAO(subscriberDAO);
|
| return ssimService;
| }
|
| public void onMessage(Message arg0) {
| // TODO Auto-generated method stub
| ObjectMessage om = (ObjectMessage) arg0;
| try {
| System.out.println("Starting message: " + om.getJMSMessageID());
| ArrayList<SsimFlight> flts = (ArrayList<SsimFlight>) om.getObject();
| getSsimService().buildFlights(flts);
| System.out.println("Completed message: " + om.getJMSMessageID());
| } catch (JMSException e) {
| // TODO Auto-generated catch block
| e.printStackTrace();
| } finally {
| }
| }
| }
Console Log:
09:13:55,386 WARN [InterceptorRegistry] applicable interceptors is non-existent for public void com.sita.wab.mdb.ssim.SSMListener.onMessage(javax.jms.Message)
| 09:13:56,333 WARN [InterceptorRegistry] applicable interceptors is non-existent for public void com.sita.wab.mdb.ssim.SSMListener.onMessage(javax.jms.Message)
| 09:13:56,361 INFO [STDOUT] Starting message: ID:JBM-50492cac-9217-467a-9544-a1b1e77b523b
| 09:13:57,310 INFO [STDOUT] Starting message: ID:JBM-3b47938a-0611-45d7-819e-982e682f5f07
| 09:13:58,100 INFO [STDOUT] Starting message: ID:JBM-90be56ab-661a-47fc-94b0-97ddd20f263a
| 09:13:58,955 INFO [STDOUT] Starting message: ID:JBM-40acff81-1248-45c4-9dfb-a17390c71b1d
| 09:13:59,891 INFO [STDOUT] Starting message: ID:JBM-7471c02f-fb50-4d63-b01b-c7e15e694210
| 09:14:00,884 INFO [STDOUT] Starting message: ID:JBM-f0d8822b-d29c-4938-8e42-fb1cf41ec12c
| 09:14:01,671 INFO [STDOUT] Starting message: ID:JBM-fb4f42ff-06d4-4071-9fbb-4ad5b17f6dfb
| 09:14:02,645 INFO [STDOUT] Starting message: ID:JBM-0c7fe953-0071-41d9-abda-dd9120ba564c
| 09:14:03,648 INFO [STDOUT] Starting message: ID:JBM-a4d8b3f9-2de7-4938-a2b1-b9058618ece6
| 09:14:05,327 INFO [STDOUT] Starting message: ID:JBM-23828e1a-a2f9-48b8-80aa-cc9e666f7c29
| 09:14:05,451 INFO [STDOUT] Starting message: ID:JBM-074ae110-0e8b-4130-a7bb-08dc5e379d96
| 09:14:07,240 INFO [STDOUT] Starting message: ID:JBM-54b1f520-fa1d-4e15-bbe2-3b1b8d81ab5e
| 09:14:07,334 INFO [STDOUT] Starting message: ID:JBM-1c32374a-986a-430e-85dc-0cbe09acfe3d
| 09:14:09,023 INFO [STDOUT] Starting message: ID:JBM-5703c26e-baf3-44c0-96d4-9e932805528c
| 09:14:09,114 INFO [STDOUT] Starting message: ID:JBM-f01f269b-b8ab-4a73-ad76-81e6022037fe
| 09:14:11,897 INFO [STDOUT] Completed message: ID:JBM-f0d8822b-d29c-4938-8e42-fb1cf41ec12c
| 09:14:11,917 INFO [STDOUT] Starting message: ID:JBM-b9f677e6-7eae-463c-8e78-7b7de728434d
| 09:14:11,926 INFO [STDOUT] Completed message: ID:JBM-0c7fe953-0071-41d9-abda-dd9120ba564c
| 09:14:11,929 INFO [STDOUT] Starting message: ID:JBM-d730996a-fe0f-45ee-95ec-30390885a4f2
| 09:14:14,889 INFO [STDOUT] Completed message: ID:JBM-a4d8b3f9-2de7-4938-a2b1-b9058618ece6
| 09:14:14,890 INFO [STDOUT] Starting message: ID:JBM-82052933-8ccb-4fcb-b680-d31aba80ea48
| 09:14:21,189 INFO [STDOUT] Completed message: ID:JBM-7471c02f-fb50-4d63-b01b-c7e15e694210
| 09:14:21,190 INFO [STDOUT] Starting message: ID:JBM-f666def7-2b21-4fbc-b92d-6c7213d75539
| 09:14:21,305 INFO [STDOUT] Completed message: ID:JBM-fb4f42ff-06d4-4071-9fbb-4ad5b17f6dfb
| 09:14:21,307 INFO [STDOUT] Starting message: ID:JBM-620331ca-804c-43e8-9f74-4a6bec3db92d
| 09:14:24,951 ERROR [TxPolicy] javax.ejb.EJBException: Failed to acquire the pool semaphore, strictTimeout=10000
| 09:14:24,959 ERROR [JmsServerSession] Unexpected error delivering message delegator->JBossMessage[20165742655045652]:PERSISTENT, deliveryId=20
| javax.ejb.EJBException: Failed to acquire the pool semaphore, strictTimeout=10000
| at org.jboss.ejb3.pool.StrictMaxPool.get(StrictMaxPool.java:126)
| at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.ejb3.security.RunAsSecurityInterceptorv2.invoke(RunAsSecurityInterceptorv2.java:94)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:75)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:65)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:262)
| at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:270)
| at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:140)
| at $Proxy129.onMessage(Unknown Source)
| at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
| at org.jboss.jms.client.container.ClientConsumer.callOnMessageStatic(ClientConsumer.java:160)
| at org.jboss.jms.client.container.SessionAspect.handleRun(SessionAspect.java:831)
| at org.jboss.aop.advice.org.jboss.jms.client.container.SessionAspect_z_handleRun_1448464820.invoke(SessionAspect_z_handleRun_1448464820.java)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.jms.client.container.ClosedInterceptor.invoke(ClosedInterceptor.java:170)
| at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:86)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.jms.client.delegate.ClientSessionDelegate.run(ClientSessionDelegate.java)
| at org.jboss.jms.client.JBossSession.run(JBossSession.java:199)
| at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:234)
| at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
| at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:260)
| at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
| at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
| at java.lang.Thread.run(Thread.java:619)
| 09:14:25,925 ERROR [TxPolicy] javax.ejb.EJBException: Failed to acquire the pool semaphore, strictTimeout=10000
| 09:14:25,928 ERROR [JmsServerSession] Unexpected error delivering message delegator->JBossMessage[20165742671806485]:PERSISTENT, deliveryId=21
| javax.ejb.EJBException: Failed to acquire the pool semaphore, strictTimeout=10000
| at org.jboss.ejb3.pool.StrictMaxPool.get(StrictMaxPool.java:126)
| at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.ejb3.security.RunAsSecurityInterceptorv2.invoke(RunAsSecurityInterceptorv2.java:94)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:75)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:65)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:262)
| at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:270)
| at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:140)
| at $Proxy129.onMessage(Unknown Source)
| at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
| at org.jboss.jms.client.container.ClientConsumer.callOnMessageStatic(ClientConsumer.java:160)
| at org.jboss.jms.client.container.SessionAspect.handleRun(SessionAspect.java:831)
| at org.jboss.aop.advice.org.jboss.jms.client.container.SessionAspect_z_handleRun_1448464820.invoke(SessionAspect_z_handleRun_1448464820.java)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.jms.client.container.ClosedInterceptor.invoke(ClosedInterceptor.java:170)
| at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:86)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
| at org.jboss.jms.client.delegate.ClientSessionDelegate.run(ClientSessionDelegate.java)
| at org.jboss.jms.client.JBossSession.run(JBossSession.java:199)
| at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:234)
| at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
| at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:260)
| at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
| at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
| at java.lang.Thread.run(Thread.java:619)
| 09:14:26,875 ERROR [TxPolicy] javax.ejb.EJBException: Failed to acquire the pool semaphore, strictTimeout=10000
| 09:14:26,875 ERROR [TxPolicy] javax.ejb.EJBException: Failed to acquire the pool semaphore, strictTimeout=10000
|
Additonal Info: (Service Methods)
This methods queues the messages:
/**
| * This method queues the flight schedule for processing
| * <p>
| *
| * @param pFlt
| * @throws ApplicationException
| */
| public void queueFlightPacket(ArrayList<SsimFlight> pFlightPacket)
| throws ApplicationException {
|
| Context jndiContext = null;
| ConnectionFactory connectionFactory = null;
| Connection connection = null;
| Session session = null;
| Destination destination = null;
| MessageProducer messageProducer = null;
| ObjectMessage message = null;
|
| try {
| jndiContext = new InitialContext();
| } catch (NamingException e) {
| System.out.println("Could not create JNDI " + "context: "
| + e.toString());
| }
|
| try {
| connectionFactory = (ConnectionFactory) jndiContext
| .lookup("ConnectionFactory");
| destination = (Queue) jndiContext.lookup("queue/SSMQueue");
| } catch (NamingException e) {
| System.out.println("JNDI lookup failed: " + e.toString());
| }
|
| try {
| connection = connectionFactory.createConnection();
| session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
| messageProducer = session.createProducer(destination);
| message = session.createObjectMessage();
| message.setObject(pFlightPacket);
| messageProducer.send(message);
| connection.close();
| } catch (JMSException e) {
| System.out.println("Exception occurred: " + e.toString());
| throw new ApplicationException();
| } finally {
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4199112#4199112
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4199112
15 years, 12 months