Yes, 
I have the Service tutorial running.

Following is my code:

  | package org.vss.jboss.service;
  | import org.jboss.annotation.ejb.Management;
  | 
  | @Management
  | public interface PollingServiceManagement {
  |     public int getPollInterval();
  | 
  |     public void setPollInterval(int pollingInterval);
  | 
  |     // Life cycle method
  |     public void create() throws Exception;
  | 
  |     public void destroy() throws Exception;
  |     
  |     public void start() throws Exception;
  |     
  |     public void stop() throws Exception;
  | }
  | 

Implementation code
import java.util.Date;
  | 
  | import org.jboss.logging.Logger;
  | import org.jboss.annotation.ejb.Service;
  | /**
  |  * @author VSrivastav
  |  * 
  |  */
  | @Service(objectName = "ejb3:service=PollingService")
  | public class PollingService implements PollingServiceManagement {
  | 
  |     Thread pollingThread = null;
  |     int pollingInterval = 30;
  |     boolean destroy;
  |     Logger log;
  |     
  |     public int getPollInterval() {
  |             // TODO Auto-generated method stub
  |             return pollingInterval;
  |     }
  | 
  |     public void setPollInterval(int pollingInterval) {
  |             this.pollingInterval = pollingInterval;
  |     }
  |     
  |     public class PollingThread extends Thread {
  |             @Override
  |             public void run() {
  |                     while(!destroy){
  |                             try{
  |                                     Date d = new Date();
  |                                     log.info(d.toString()+": Sleeping for 
"+pollingInterval+" seconds");
  |                                     sleep(pollingInterval*1000);
  |                                     log.info("Starting Poll...");
  |                             }catch(InterruptedException ex){
  |                                     log.info("PollingThread interrupted: 
"+ex.getMessage());
  |                             }
  |                     }
  |                     log.info("PollingThread stopped.");
  |             }
  |     }
  | 
  |     public void create() throws Exception {
  |             log = Logger.getLogger(this.getClass());
  |             log.info("PollingService - Creating");
  |     }
  | 
  |     public void destroy() throws Exception {
  |             log.info("PollingService - Destroying");                
  |     }
  | 
  |     public void start() throws Exception {
  |             log.info("PollingService - Starting poll thread");      
  |             pollingThread = new PollingThread();
  |             pollingThread.start();          
  |     }
  | 
  |     public void stop() throws Exception {
  |             log.info("PollingService - Stopping poll thread");
  |             destroy = true;
  |             if(pollingThread != null && pollingThread.isAlive())
  |                     pollingThread.interrupt();              
  |     }
  | }
  | 

The Service is deployed as ejb3Service.ejb3 file. It contains just a 
META-INF/Manifest.mf and my class files.



View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3917716#3917716

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3917716


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to