Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*     */ package org.quartz.ee.jmx.jboss;
  /*     */ 
  /*     */ import java.io.ByteArrayInputStream;
  /*     */ import java.io.ByteArrayOutputStream;
  /*     */ import java.io.IOException;
  /*     */ import java.io.PrintWriter;
  /*     */ import java.io.StringWriter;
  /*     */ import java.util.Properties;
  /*     */ import javax.naming.InitialContext;
 /*     */ import javax.naming.Name;
 /*     */ import javax.naming.NameParser;
 /*     */ import javax.naming.NamingException;
 /*     */ import  org.jboss.logging.Logger;
 /*     */ import  org.jboss.naming.NonSerializableFactory;
 /*     */ import  org.jboss.system.ServiceMBeanSupport;
 /*     */ import org.quartz.Scheduler;
 /*     */ import org.quartz.SchedulerConfigException;
 /*     */ import org.quartz.impl.StdSchedulerFactory;
 /*     */ 
 /*     */ public class QuartzService extends ServiceMBeanSupport
 /*     */   implements QuartzServiceMBean
 /*     */ {
 /*     */   private Properties properties;
 /*     */   private StdSchedulerFactory schedulerFactory;
 /*     */   private String jndiName;
 /*     */   private String propertiesFile;
 /*     */   private boolean error;
 /*     */   private boolean useProperties;
 /*     */   private boolean usePropertiesFile;
 /*     */ 
 /*     */   public QuartzService()
 /*     */   {
 /*  84 */     this. = false;
 /*     */ 
 /*  87 */     this. = false;
 /*  88 */     this. = "";
 /*     */ 
 /*  91 */     this. = false;
 /*  92 */     this. = new Properties();
 /*     */ 
 /*  95 */     this. = "Quartz";
 /*     */   }
 /*     */ 
 /*     */   public void setJndiName(String jndiName)
 /*     */     throws Exception
 /*     */   {
 /* 107 */     String oldName = this.;
 /* 108 */     this. = jndiName;
 /*     */ 
 /* 110 */     if (super.getState() == 3) {
 /* 111 */       unbind(oldName);
 /*     */       try
 /*     */       {
 /* 114 */         rebind();
 /*     */       } catch (NamingException ne) {
 /* 116 */         this..error(captureStackTrace(ne));
 /*     */ 
 /* 118 */         throw new SchedulerConfigException("Failed to rebind Scheduler - "ne);
 /*     */       }
 /*     */     }
 /*     */   }
 /*     */ 
 /*     */   public String getJndiName()
 /*     */   {
 /* 125 */     return this.;
 /*     */   }
 /*     */ 
 /*     */   public String getName() {
 /* 129 */     return "QuartzService(" + this. + ")";
 /*     */   }
 /*     */ 
 /*     */   public void setProperties(String properties) {
 /* 133 */     if (this.) {
 /* 134 */       this..error("Must specify only one of 'Properties' or 'PropertiesFile'");
 /*     */ 
 /* 137 */       this. = true;
 /*     */ 
 /* 139 */       return;
 /*     */     }
 /*     */ 
 /* 142 */     this. = true;
 /*     */     try
 /*     */     {
 /* 145 */       ByteArrayInputStream bais = new ByteArrayInputStream(properties.getBytes());
 /*     */ 
 /* 147 */       this. = new Properties();
 /* 148 */       this..load(bais);
 /*     */     }
 /*     */     catch (IOException ioe) {
 /*     */     }
 /*     */   }
 /*     */ 
 /*     */   public String getProperties() {
 /*     */     try {
 /* 156 */       ByteArrayOutputStream baos = new ByteArrayOutputStream();
 /* 157 */       this..store(baos"");
 /*     */ 
 /* 159 */       return new String(baos.toByteArray());
 /*     */     } catch (IOException ioe) {
/*     */     }
/* 162 */     return "";
/*     */   }
/*     */ 
/*     */   public void setPropertiesFile(String propertiesFile)
/*     */   {
/* 167 */     if (this.) {
/* 168 */       this..error("Must specify only one of 'Properties' or 'PropertiesFile'");
/*     */ 
/* 171 */       this. = true;
/*     */ 
/* 173 */       return;
/*     */     }
/*     */ 
/* 176 */     this. = true;
/*     */ 
/* 178 */     this. = propertiesFile;
/*     */   }
/*     */ 
/*     */   public String getPropertiesFile() {
/* 182 */     return this.;
/*     */   }
/*     */ 
/*     */   public void createService() throws Exception {
/* 186 */     this..info("Create QuartzService(" + this. + ")...");
/*     */ 
/* 188 */     if (this.) {
/* 189 */       this..error("Must specify only one of 'Properties' or 'PropertiesFile'");
/*     */ 
/* 192 */       throw new Exception("Must specify only one of 'Properties' or 'PropertiesFile'");
/*     */     }
/*     */ 
/* 196 */     this. = new StdSchedulerFactory();
/*     */     try
/*     */     {
/* 199 */       if (this.) {
/* 200 */         this..initialize(this.);
/*     */       }
/*     */ 
/* 203 */       if (this.)
/* 204 */         this..initialize(this.);
/*     */     }
/*     */     catch (Exception e) {
/* 207 */       this..error(captureStackTrace(e));
/*     */ 
/* 209 */       throw new SchedulerConfigException("Failed to initialize Scheduler - "e);
/*     */     }
/*     */ 
/* 213 */     this..info("QuartzService(" + this. + ") created.");
/*     */   }
/*     */ 
/*     */   public void destroyService() throws Exception {
/* 217 */     this..info("Destroy QuartzService(" + this. + ")...");
/*     */ 
/* 219 */     this. = null;
/*     */ 
/* 221 */     this..info("QuartzService(" + this. + ") destroyed.");
/*     */   }
/*     */ 
/*     */   public void startService() throws Exception {
/* 225 */     this..info("Start QuartzService(" + this. + ")...");
/*     */     try
/*     */     {
/* 228 */       rebind();
/*     */     } catch (NamingException ne) {
/* 230 */       this..error(captureStackTrace(ne));
/*     */ 
/* 232 */       throw new SchedulerConfigException("Failed to rebind Scheduler - "ne);
/*     */     }
/*     */ 
/*     */     try
/*     */     {
/* 237 */       Scheduler scheduler = this..getScheduler();
/*     */ 
/* 239 */       scheduler.start();
/*     */     } catch (Exception e) {
/* 241 */       this..error(captureStackTrace(e));
/*     */ 
/* 243 */       throw new SchedulerConfigException("Failed to start Scheduler - "e);
/*     */     }
/*     */ 
/* 247 */     this..info("QuartzService(" + this. + ") started.");
/*     */   }
/*     */ 
/*     */   public void stopService() throws Exception {
/* 251 */     this..info("Stop QuartzService(" + this. + ")...");
/*     */     try
/*     */     {
/* 254 */       Scheduler scheduler = this..getScheduler();
/*     */ 
/* 256 */       scheduler.shutdown();
/*     */     } catch (Exception e) {
/* 258 */       this..error(captureStackTrace(e));
/*     */ 
/* 260 */       throw new SchedulerConfigException("Failed to shutdown Scheduler - ");
/*     */     }
/*     */ 
/* 264 */     unbind(this.);
/*     */ 
/* 266 */     this..info("QuartzService(" + this. + ") stopped.");
/*     */   }
/*     */ 
/*     */   private String captureStackTrace(Throwable throwable) {
/* 270 */     StringWriter sw = new StringWriter();
/* 271 */     throwable.printStackTrace(new PrintWriter(swtrue));
/*     */ 
/* 273 */     return sw.toString();
/*     */   }
/*     */ 
/*     */   private void rebind() throws Exception
/*     */   {
/* 278 */     InitialContext rootCtx = new InitialContext();
/* 279 */     Name fullName = rootCtx.getNameParser("").parse(this.);
/* 280 */     Scheduler scheduler = this..getScheduler();
/* 281 */     NonSerializableFactory.rebind(fullNameschedulertrue);
/*     */   }
/*     */ 
/*     */   private void unbind(String jndiName)
/*     */   {
/*     */     try
/*     */     {
/* 288 */       InitialContext rootCtx = new InitialContext();
/* 289 */       rootCtx.unbind(jndiName);
/* 290 */       NonSerializableFactory.unbind(jndiName);
/*     */     }
/*     */     catch (NamingException e)
/*     */     {
/* 294 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/thirdparty-all.jar
 * Qualified Name:     org.quartz.ee.jmx.jboss.QuartzService
 * JD-Core Version:    0.6.0
 */
New to GrepCode? Check out our FAQ X