Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2010, FuseSource Corp. All rights reserved.
 
 package org.fusesource.fabric.stream.log;
 
 

Implements a OGSi ManagedServiceFactory so that we can easily configure HttpSimulators easily across a fabric cluster.

Author(s):
Hiram Chirino
public class HttpSimulatorFactory implements ManagedServiceFactory {
    @Override
    public String getName() {
        return "Http Simulator Factory";
    }
    @Override
    synchronized public void updated(String pidDictionary dictionarythrows ConfigurationException {
        try {
            deleted(pid);
            .put(pidcreateSimulator(toMap(dictionary)));
        } catch (Throwable e) {
            throw (ConfigurationExceptionnew ConfigurationException(null"Unable to parse configuration: " + e.getMessage()).initCause(e);
        }
    }
    @Override
    synchronized public void deleted(String s) {
        HttpSimulator simulator = .remove(s);
        if (simulator != null) {
            simulator.stop();
        }
    }
    public void destroy() {
        forString key : new ArrayList<String>(.keySet()) ) {
            deleted(key);
        }
    }
    private HttpSimulator createSimulator(HashMap<StringStringproperties) {
        HttpSimulator simulator = new HttpSimulator();
        IntrospectionSupport.setProperties(simulatorproperties);
        simulator.start();
        return simulator;
    }
    public static HashMap<StringStringtoMap(Dictionary dictionary) {
        HashMap<StringStringrc = new HashMap<StringString>();
        Enumeration ek = dictionary.keys();
        while (ek.hasMoreElements()) {
            Object key = ek.nextElement();
            Object value = dictionary.get(key);
            if(key!=null && value!=null) {
                rc.put(key.toString(), value.toString());
            }
        }
        return rc;
    }
New to GrepCode? Check out our FAQ X