Package com.almende.eve.state

Examples of com.almende.eve.state.StateFactory


   * .eve.config.Config, java.lang.String)
   */
  @Override
  public StateFactory getStateFactoryFromConfig(final Config config,
      String configName) {
    StateFactory result = null;
    // get the class name from the config file
    // first read from the environment specific configuration,
    // if not found read from the global configuration
   
    String className = config.get(configName, "class");
    if (className == null) {
      if (!configName.equals("state")) {
        // Provide fallback to state if other type doesn't exist;
        configName = "state";
        className = config.get(configName, "class");
      }
      if (className == null) {
        throw new IllegalArgumentException("Config parameter '"
            + config + ".class' missing in Eve configuration.");
      }
    }
   
    try {
      // get the class
      final Class<?> stateClass = Class.forName(className);
      if (!ClassUtil.hasInterface(stateClass, StateFactory.class)) {
        throw new IllegalArgumentException("State factory class "
            + stateClass.getName() + " must extend "
            + State.class.getName());
      }
     
      // instantiate the state factory
      final Map<String, Object> params = config.get(configName);
      result = (StateFactory) stateClass.getConstructor(Map.class)
          .newInstance(params);
     
      LOG.info("Initialized state factory: " + result.toString());
    } catch (final Exception e) {
      LOG.log(Level.WARNING, "", e);
    }
    return result;
  }
View Full Code Here


            " must extend " + State.class.getName());
      }
 
      // instantiate the state factory
      Map<String, Object> params = config.get(configName);
      StateFactory stateFactory = (StateFactory) stateClass
          .getConstructor(AgentFactory.class, Map.class )
          .newInstance(this, params);

      setStateFactory(stateFactory);
      logger.info("Initialized state factory: " + stateFactory.toString());
    }
    catch (Exception e) {
      e.printStackTrace();
    }   
  }
View Full Code Here

   * .eve.config.Config, java.lang.String)
   */
  @Override
  public StateFactory getStateFactoryFromConfig(final Config config,
      String configName) {
    StateFactory result = null;
    // get the class name from the config file
    // first read from the environment specific configuration,
    // if not found read from the global configuration
   
    String className = config.get(configName, "class");
    if (className == null) {
      if (!configName.equals("state")) {
        // Provide fallback to state if other type doesn't exist;
        configName = "state";
        className = config.get(configName, "class");
      }
      if (className == null) {
        throw new IllegalArgumentException("Config parameter '"
            + config + ".class' missing in Eve configuration.");
      }
    }
   
    try {
      // get the class
      final Class<?> stateClass = Class.forName(className);
      if (!ClassUtil.hasInterface(stateClass, StateFactory.class)) {
        throw new IllegalArgumentException("State factory class "
            + stateClass.getName() + " must extend "
            + State.class.getName());
      }
     
      // instantiate the state factory
      final Map<String, Object> params = config.get(configName);
      result = (StateFactory) stateClass.getConstructor(Map.class)
          .newInstance(params);
     
      LOG.info("Initialized state factory: " + result.toString());
    } catch (final Exception e) {
      LOG.log(Level.WARNING, "", e);
    }
    return result;
  }
View Full Code Here

     *
     * @throws IOException Signals that an I/O exception has occurred.
     */
    MyCookieStore() throws IOException {
      final AgentHost host = AgentHost.getInstance();
      StateFactory factory = null;
      if (host.getConfig() != null) {
        factory = host.getStateFactoryFromConfig(host.getConfig(),
            "cookies");
      }
      if (factory == null) {
        factory = host.getStateFactory();
      }
      if (factory.exists(COOKIESTORE)) {
        myState = factory.get(COOKIESTORE);
      } else {
        myState = factory.create(COOKIESTORE);
        myState.setAgentType(CookieStore.class);
      }
    }
View Full Code Here

            + State.class.getName());
      }

      // instantiate the state factory
      Map<String, Object> params = config.get(configName);
      StateFactory stateFactory = (StateFactory) stateClass
          .getConstructor(AgentFactory.class, Map.class).newInstance(
              this, params);

      setStateFactory(stateFactory);
      logger.info("Initialized state factory: " + stateFactory.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

            + State.class.getName());
      }
     
      // instantiate the state factory
      Map<String, Object> params = config.get(configName);
      StateFactory sf = (StateFactory) stateClass.getConstructor(
          Map.class).newInstance(params);
     
      setStateFactory(sf);
      LOG.info("Initialized state factory: " + sf.toString());
    } catch (Exception e) {
      LOG.log(Level.WARNING, "", e);
    }
  }
View Full Code Here

   * .eve.config.Config, java.lang.String)
   */
  @Override
  public StateFactory getStateFactoryFromConfig(final Config config,
      String configName) {
    StateFactory result = null;
    // get the class name from the config file
    // first read from the environment specific configuration,
    // if not found read from the global configuration
   
    String className = config.get(configName, "class");
    if (className == null) {
      if (!configName.equals("state")) {
        // Provide fallback to state if other type doesn't exist;
        configName = "state";
        className = config.get(configName, "class");
      }
      if (className == null) {
        throw new IllegalArgumentException("Config parameter '"
            + config + ".class' missing in Eve configuration.");
      }
    }
   
    try {
      // get the class
      final Class<?> stateClass = Class.forName(className);
      if (!ClassUtil.hasInterface(stateClass, StateFactory.class)) {
        throw new IllegalArgumentException("State factory class "
            + stateClass.getName() + " must extend "
            + State.class.getName());
      }
     
      // instantiate the state factory
      final Map<String, Object> params = config.get(configName);
      result = (StateFactory) stateClass.getConstructor(Map.class)
          .newInstance(params);
     
      LOG.info("Initialized state factory: " + result.toString());
    } catch (final Exception e) {
      LOG.log(Level.WARNING, "", e);
    }
    return result;
  }
View Full Code Here

            " must extend " + State.class.getName());
      }
 
      // instantiate the state factory
      Map<String, Object> params = config.get(configName);
      StateFactory stateFactory = (StateFactory) stateClass
          .getConstructor(AgentFactory.class, Map.class )
          .newInstance(this, params);

      setStateFactory(stateFactory);
      logger.info("Initialized state factory: " + stateFactory.toString());
    }
    catch (Exception e) {
      e.printStackTrace();
    }   
  }
View Full Code Here

TOP

Related Classes of com.almende.eve.state.StateFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.