-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Configure Hibernate Search/ActiveMQ for Amazon EC2
PostPosted: Sat Jul 23, 2011 12:51 am 
Newbie

Joined: Sat Jul 23, 2011 12:28 am
Posts: 8
Hi guys,

I'm working on a project that is deployed to Tomcat servers on Amazon EC2 and used Hibernate Search. I'm trying to follow the instructions in this article: http://community.jboss.org/wiki/ClusteringUsingActiveMQAndTomcat, but I've got stuck at the getSession() method of the AbstractJMSHibernateSearchController class.

Here's the class that extends the AbstractJMSHibernateSearchController class in my master application:

Code:
public class HSearchListener extends AbstractJMSHibernateSearchController {     
    // My problem is here
    @Autowired     
    private SessionFactory sessionFactory;           

    @Override     
    protected Session getSession() {
        return sessionFactory.getCurrentSession();     
    }       
    ///

    @Override     
    protected void cleanSessionIfNeeded(Session arg0) { }

    public void register() {
        // Copied from the referenced article         
        try {               
            Context initCtx = new InitialContext();                 
            // Look up for connection factory & create connection, session
            ConnectionFactory connectionFactory = (ConnectionFactory)initCtx.lookup("java:comp/env/jms/ConnectionFactory");               
            Connection connection = connectionFactory.createConnection();       
            connection.start();               
            javax.jms.Session session = connection.createSession(true, 0);                 
            // Look up for destination and set listener               
            Queue queue = (Queue) initCtx.lookup("java:comp/env/queue/hibernatesearch");
            MessageConsumer consumer = session.createConsumer(queue);
            consumer.setMessageListener(this);           
        } catch (Exception ex) {               
            // Looging
        }     
    }
}


and the Spring bean configuration (we apply Spring3 to our application) for SessionFactory:

Code:
<bean id="clientSessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="clientDataSource" />
      <property name="packagesToScan" value="tc.model" />
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <!--<prop key="hibernate.hbm2ddl.auto">validate</prop> -->            

            <!-- JMS configuration -->
            <prop key="hibernate.search.default.sourceBase">d:/lucene/mastervolume/lucenedirs/mastercopy</prop>
            <prop key="hibernate.search.default.refresh">10</prop>
            <!-- Master node configuration -->
            <prop key="hibernate.search.default.indexBase">d:/lucene/master/lucenedirs</prop>
            <prop key="hibernate.search.default.directory_provider">filesystem-master</prop>
            
            <!-- Slave nodes configuration -->
            <!-- <prop key="hibernate.search.default.indexBase">d:/lucene/slave/lucenedirs</prop> -->
            <!-- <prop key="hibernate.search.default.directory_provider">filesystem-slave</prop> -->
            <!-- <prop key="hibernate.search.worker.backend">jms</prop> -->
            <!-- <prop key="hibernate.search.worker.jms.connection_factory">java:comp/env/jms/ConnectionFactory</prop> -->
            <!-- <prop key="hibernate.search.worker.jms.queue">java:comp/env/queue/hibernatesearch</prop> -->
            <!-- <prop key="hibernate.search.worker.execution">async</prop> -->
            <!-- <prop key="hibernate.search.worker.thread_pool.size">2</prop> -->
            <!-- <prop key="hibernate.search.worker.buffer_queue.max">10</prop> -->
         </props>
      </property>
   </bean>


My problem is when the HSearchListener call the getSession() method to process messages from slave nodes, it throws null exception due to null value of sessionFactory. It seems the bean can not be wired up for some reason.
It's really great for me to receive your helps to overcome this problem in particular to find some other ways to setup Hibernate Search on Amazon EC2 in general.

Actually, I also raised my problem in the article http://community.jboss.org/wiki/ClusteringUsingActiveMQAndTomcat as a comment. I wanna post it here too in the hope to receive more helps.

Thanks a lot, everybody.


Top
 Profile  
 
 Post subject: Re: Configure Hibernate Search/ActiveMQ for Amazon EC2
PostPosted: Sat Jul 23, 2011 8:23 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello, welcome.

If it's a Spring error I can't help you (not an expert!), but maybe the SessionFactory won't start because of some other configuration error.
I assume you didn't find error messages in the log?

Also, are you using windows machines on EC2? I noticed the windows-style path in the configuration of the Lucene indexes, it seems a bit odd.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Configure Hibernate Search/ActiveMQ for Amazon EC2
PostPosted: Fri Aug 05, 2011 12:16 pm 
Newbie

Joined: Sat Jul 23, 2011 12:28 am
Posts: 8
Hi,

Thanks a lot for your answer.
Actually, the configurations in my post are for my local Windows machine. I just want to do some testings before deploying to Linux server on Amazon (sorry for making confusion there).

With the SessionFactory problem, maybe you were right to say it was a kind of configuration error. Unfortunately, I have not figured it out and came up with a workaround: copy and modify the source codes of AbstartJMSHibernateSearchController class, replace the getSession() method with some configuration hard codes.

Here is my new classes:
Code:
/* Copy codes from class AbstartJMSHibernateSearchController of Emmanuel Bernard */
public class HSearchJMSHibernateSearchController implements MessageListener {
   private static final Logger log = LoggerFactory.make();

   /**
    * Process the Hibernate Search work queues received
    */
   @SuppressWarnings("unchecked")
   public void onMessage(Message message) {
      if ( !( message instanceof ObjectMessage ) ) {
         log.error( "Incorrect message type: {}", message.getClass() );
         return;
      }
      ObjectMessage objectMessage = (ObjectMessage) message;
      List<LuceneWork> queue;
      try {
         queue = (List<LuceneWork>) objectMessage.getObject();
      }
      catch (JMSException e) {
         log.error( "Unable to retrieve object from message: " + message.getClass(), e );
         return;
      }
      catch (ClassCastException e) {
         log.error( "Illegal object retrieved from message", e );
         return;
      }
      Runnable worker = getWorker( queue );
      worker.run();
   }

   private Runnable getWorker(List<LuceneWork> queue) {
      Runnable processor = null;

       /* Modified code: Directly get the SearchFactoryImplementor */
      SearchFactoryImplementor factory = HSearchContextHelper.getSearchFactory();
      processor = factory.getBackendQueueProcessorFactory().getProcessor( queue );
      
      return processor;
   }

   @PostConstruct
   public void initialize() {
      //init the source copy process
      //TODO actually this is probably wrong since this is now part of the DP
   }

   @PreDestroy
   public void shutdown() {
      //stop the source copy process
      //TODO actually this is probably wrong since this is now part of the DP
   }
}

Code:
public abstract class HSearchContextHelper {

   public static SearchFactoryImplementor getSearchFactory() {
      FullTextIndexEventListener listener = new FullTextIndexEventListener(Installation.SINGLE_INSTANCE);      
      Configuration cfg = new Configuration();
      Properties properties = new Properties();
      
      properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
      properties.setProperty("hibernate.show_sql", "false");
      properties.setProperty("hibernate.format_sql", "false");
      properties.setProperty("hibernate.generate_statistics", "true");
      properties.setProperty("hibernate.search.default.sourceBase", "/mnt/lucenedirs/master");
      properties.setProperty("hibernate.search.default.refresh", "30");
      properties.setProperty("hibernate.search.default.indexBase", "/usr/lucenedirs/master");
      properties.setProperty("hibernate.search.default.directory_provider", "filesystem-master");
      cfg.setProperties(properties);
      
      cfg.addAnnotatedClass(Requirement.class);
      cfg.addAnnotatedClass(TestCase.class);
      cfg.addAnnotatedClass(Defect.class);   
      cfg.addAnnotatedClass(Project.class);
      
      cfg.buildMappings();
      cfg.buildSettings();

      listener.initialize(cfg);
      return listener.getSearchFactoryImplementor();
   }
}


Honestly, I'm feeling good with this workaround and not sure whether it makes any sense to you guys, but at least it seems to work fine. Do you have any advice for that?

Thanks a lot and Best regards,


Top
 Profile  
 
 Post subject: Re: Configure Hibernate Search/ActiveMQ for Amazon EC2
PostPosted: Fri Aug 05, 2011 1:49 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
It seems you're initializing a new SearchFactory instance for every message you receive. That's going to be very slow, starting a SearchFactory might take close to a second, while reusing one could handle some thousand messages per second.. you're killing performance, but it might work.

I'd move that code in the initialize() method, and make sure the getWorker() reuses the same SearchFactory instance.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.