Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2008 EsperTech, Inc. All rights reserved. * http://esper.codehaus.org * http://www.espertech.com * ---------------------------------------------------------------------------------- * The software in this package is published under the terms of the GPL license * a copy of which has been included with this distribution in the license.txt file. * /
  
  package com.espertech.esperio.socket;
 
 
 import java.io.File;
 import java.net.URL;
 
 public class EsperIOSocketAdapterPlugin implements PluginLoader
 {
     private static Log log = LogFactory.getLog(EsperIOSocketAdapterPlugin.class);
 
     private static final String ESPERIO_SOCKET_CONFIG_FILE = "esperio.socket.configuration.file";
 
     private PluginLoaderInitContext context;
 
     public void init(PluginLoaderInitContext context)
     {
         this. = context;
     }
 
     public void postInitialize()
     {
         ConfigurationSocketAdapter adapterConfig;
         if (.getConfigXml() != null) {
             adapterConfig = fromXml(.getConfigXml());
         }
         else {
             adapterConfig = fromExternalFile();
         }
 
         .info("Starting Socket Adapter");
          = new EsperIOSocketAdapter(adapterConfig.getEpServiceProvider().getURI());
         .start();
     }
 
     public void destroy()
     {
         if ( != null)
         {
             .destroy();
         }
          = null;
     }
 
     private ConfigurationSocketAdapter fromXml(String xml) {
         ConfigurationSocketAdapter adapter = new ConfigurationSocketAdapter();
         return adapter.configureFromString(xml);
     }
 
 
         // obtain config file name
         if (configFile == null)
         {
             String message = "Required initialization property '" +  + "' is not provided";
             .error(message);
             throw new RuntimeException(message);
         }
 
         // resolve config file
         URL urlConfigFile;
         try
         {
             urlConfigFile = resolveURL(configFile);
         }
         catch (Exception ex)
         {
             String message = "Error resolving config file from classpath or as a URL: " + ex.getMessage();
             .error(messageex);
             throw new RuntimeException(messageex);
         }
 
         if (urlConfigFile == null)
         {
             String message = "Configuration file could not be resolved from '" + urlConfigFile + "'";
             .error(message);
             throw new RuntimeException(message);
         }
 
         // parse config file
         ConfigurationSocketAdapter config = new ConfigurationSocketAdapter();
         try
         {
             config.configure(urlConfigFile);
         }
        catch (RuntimeException ex)
        {
            String message = "Configuration file read error for config file '" + urlConfigFile + "': " + ex.getMessage();
            .error(messageex);
            throw new RuntimeException(messageex);
        }
        return config;
    }
    private URL resolveURL(String configthrows Exception
    {
        URL url = this.getClass().getClassLoader().getResource(config);
        if (url != null)
        {
            return url;
        }
        url = Thread.currentThread().getContextClassLoader().getResource(config);
        if (url != null)
        {
            return url;
        }
        File file = new File(config);
        if (!file.isAbsolute()) {
            String espereeBase = System.getProperty("esperee.base");
            file = new File(espereeBaseconfig);
        }
        if (file.exists()) {
            return file.toURI().toURL();
        }
        return new URL(config);
    }
New to GrepCode? Check out our FAQ X