Oh I see... maybe something inside the dao wasn't initialized/injected?

[]s,
Thiago.


On Tue, Mar 10, 2015 at 6:15 AM, Matej <[email protected]> wrote:

> UniversalConfigurationDao is a Stateless Bean.
>
> BRM
>
>
> 2015-03-10 10:51 GMT+01:00 Thiago Veronezi <[email protected]>:
>
> > Hi,
> >
> > Adding  @DependsOn("UniversalConfigurationDao") in your singleton bean
> does
> > not fix the problem?
> >
> > @Singleton
> > @Startup
> > @ConcurrencyManagement(ConcurrencyManagementType.BEAN)
> > @DependsOn("UniversalConfigurationDao")
> > public class UniversalConfigurationService {
> >
> >     @Inject
> >     UniversalConfigurationDao configDao;
> >
> >     private ConcurrentHashMap<Integer, ConcurrentHashMap<Integer,
> > ConfigValue>> configCache = new ConcurrentHashMap<>();
> >
> >     @PostConstruct
> >     public void init() {
> >         this.configCache = configDao.getAllConfigurations();
> >     }
> > }
> >
> > []s,
> > Thiago.
> >
> >
> > On Tue, Mar 10, 2015 at 4:14 AM, Matej <[email protected]> wrote:
> >
> > > Hi Romain.
> > >
> > > I don't really understand your solution. Can you please provide me with
> > > simple exmaple.... So I'll understand.
> > >
> > > BR
> > >
> > > MAtej
> > >
> > > 2015-03-09 22:59 GMT+01:00 Romain Manni-Bucau <[email protected]>:
> > >
> > > > Why not using a dependson singleton as delegate in your mdb as
> > > mentionned?
> > > > Fast and reliable  as fix imo
> > > > Le 9 mars 2015 22:13, "Matej" <[email protected]> a écrit :
> > > >
> > > > > Would something like that help. That's probably something what
> David
> > > > meant.
> > > > >
> > > > > @Singleton
> > > > > @Startup
> > > > > @Lock(LockType.READ)
> > > > > @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
> > > > > public class UniversalConfigurationService {
> > > > >
> > > > >     @Inject
> > > > >     UniversalConfigurationDao configDao;
> > > > >
> > > > >     private ConcurrentHashMap<Integer, ConcurrentHashMap<Integer,
> > > > > ConfigValue>> configCache = new ConcurrentHashMap<>();
> > > > >
> > > > >     @PostConstruct
> > > > > @Lock(LockType.WRITE) //probably not nedded right?
> > > > >     public void init() {
> > > > >         this.configCache = configDao.getAllConfigurations();
> > > > >     }
> > > > > }
> > > > >
> > > > > 2015-03-09 19:10 GMT+01:00 Matej <[email protected]>:
> > > > >
> > > > > > I added a short stacktrace. Will try to provide better one.
> Somehow
> > > is
> > > > > > seems, like the system is not fully initialized, like some
> > injection
> > > > > > missing.. Without the (configurationService.getBoolean,
> everything
> > > > loads
> > > > > > normally. Is the MDB system initialized before EJBs?
> > > > > >
> > > > > >
> > > > > > Here is the Singleton snippet:
> > > > > > @Singleton
> > > > > > @Startup
> > > > > > @ConcurrencyManagement(ConcurrencyManagementType.BEAN)
> > > > > > public class UniversalConfigurationService {
> > > > > >
> > > > > >     @Inject
> > > > > >     UniversalConfigurationDao configDao;
> > > > > >
> > > > > >     private ConcurrentHashMap<Integer, ConcurrentHashMap<Integer,
> > > > > > ConfigValue>> configCache = new ConcurrentHashMap<>();
> > > > > >
> > > > > >     @PostConstruct
> > > > > >     public void init() {
> > > > > >         this.configCache = configDao.getAllConfigurations();
> > > > > >     }
> > > > > > }
> > > > > >
> > > > > > and here te MDB
> > > > > >
> > > > > > MessageDriven(activationConfig = {
> > > > > >     @ActivationConfigProperty(propertyName = "destinationType",
> > > > > > propertyValue = "javax.jms.Queue"),
> > > > > >     @ActivationConfigProperty(propertyName = "destination",
> > > > propertyValue
> > > > > > = "EtaStatisticalRes")})
> > > > > > @DependsOn("UniversalConfigurationService")
> > > > > > public class EtaStatisticalResHandler implements MessageListener
> {
> > > > > >
> > > > > >     @Inject
> > > > > >     public Logger logger;
> > > > > >
> > > > > >     @Inject
> > > > > >     UniversalConfigurationService configurationService;
> > > > > >
> > > > > >     @Override
> > > > > >     public void onMessage(Message message) {
> > > > > >
> > > > > >         if (configurationService.getBoolean(ETA.getCode(),
> > > > > > EMBEDDED_ETA_REPORTING.getCode())) {
> > > > > >             return;
> > > > > >         }
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > 2015-03-08 5:31 GMT+01:00 David Blevins <[email protected]
> >:
> > > > > >
> > > > > >> The @DependsOn annotation only works for other @Singleton beans.
> > > > > >>
> > > > > >> Definitely use CONTAINER concurrency.  Understand that this code
> > is
> > > > just
> > > > > >> a plain jvm ReentrantReadWriteLock under the covers.  It would
> be
> > > hard
> > > > > to
> > > > > >> do much better.
> > > > > >>
> > > > > >>  -
> > > > > >>
> > > > >
> > > >
> > >
> >
> http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/ReentrantReadWriteLock.html
> > > > > >>
> > > > > >> All methods annotated with an @Lock(READ) acquire a read lock.
> > All
> > > > > >> methods annotated with @Lock(WRITE) acquire a write lock.
> > > > > >>
> > > > > >> That said, if you're already doing the configuration
> > initialization
> > > in
> > > > > >> the @PostConstruct of the @Singleton, this issue shouldn't
> exist.
> > > > > >>
> > > > > >> Can you paste the stacktrace of your NPE?
> > > > > >>
> > > > > >>
> > > > > >> --
> > > > > >> David Blevins
> > > > > >> http://twitter.com/dblevins
> > > > > >> http://www.tomitribe.com
> > > > > >>
> > > > > >> On Mar 7, 2015, at 3:51 AM, Matej <[email protected]> wrote:
> > > > > >>
> > > > > >> > Hi everybody.
> > > > > >> >
> > > > > >> > We have an annoying problem on our production system. We have
> an
> > > > > >> > Configuration Singleton which reads config things from DB.
> Then
> > in
> > > > one
> > > > > >> MDB
> > > > > >> > we inject this Singleton to control operation based on
> configs.
> > > Our
> > > > > >> problem
> > > > > >> > is that the system is quite heavely loadded and while the
> system
> > > > > >> startups
> > > > > >> > already MDB recievs onMessage events while the Singleton still
> > > > > >> initliazes.
> > > > > >> > Which produces some NPEs and system doesn't boot.
> > > > > >> >
> > > > > >> > The depneds on annotation seems not to help. We are doing BEAN
> > > > > >> conncurency
> > > > > >> > management could this be the issue? And the Singleton has an
> > > > > >> Postconstruct
> > > > > >> > annotation.
> > > > > >> >
> > > > > >> > Anyone has any pattern or tips how to handle this type of
> > > scenario.
> > > > > >> >
> > > > > >> > BR
> > > > > >> >
> > > > > >> > Matej
> > > > > >>
> > > > > >>
> > > > > >
> > > > >
> > > >
> > >
> >
>

Reply via email to