Package org.jboss.fresh.events

Examples of org.jboss.fresh.events.EventCentral


    }

    Context c = getShell().getContext();

    EventCentral ec = (EventCentral) c.get("EventCentral");

    if (ec == null) {
      error("EventCentral not bound in context.");
      return;
    }


    switch (action) {

      case ADD:
        {

          ClassLoader cl = Thread.currentThread().getContextClassLoader();
          Class liscls = null;
          try {
            liscls = cl.loadClass(aclazz);
          } catch (ClassNotFoundException e) {
            error("No such class: " + aclazz);
            return;
          }

          EventListener lis = null;

          // if extra params

          // load class and find constructor that takes one String as parameter


          try {
            // create Listener
            lis = (EventListener) liscls.newInstance();
          //} catch (NoSuchMethodException e) {
          //  error("No constructor for extra parameters found: " + liscls);
          //  return;

          } catch (InstantiationException e) {
            error("Could not instantiate class: " + liscls);
            return;

          } catch (IllegalAccessException e) {
            error("Not allowed to instantiate class: " + liscls);
            return;
          }


          String origin = ec.produceOrigin(compName);

          // register it with the pattern
          ec.registerEventListener(origin, lis, patterns);
         
          BufferObjectWriter boo = new BufferObjectWriter(getStdOut());
          boo.writeObject(origin);
          boo.flush();

        }
        break;

      case LIST:
        {
          Iterator it = ec.listenersIterator();
          while (it.hasNext()) {
            Map.Entry ent = (Map.Entry) it.next();
            Object key = ent.getKey();
            Object val = ent.getValue();
            err.println(key + " = " + val);
          }
        }
        break;

      case DELETE:
        {
          // find listener whose string representation equals
          // then call unregister
          Iterator it = ec.listenersIterator();
          EventListener lis = null;
          while (it.hasNext()) {
            Map.Entry ent = (Map.Entry) it.next();
            lis = (EventListener) ent.getKey();

            if (String.valueOf(lis).equals(dlisStr)) break;
          }

          if (lis == null) {
            if (canThrowEx()) {
              throw new Exception("Event listener not registered: " + dlisStr);
            } else {
              err.println("Event listener not registered: " + dlisStr);
              log.debug("done");
              return;
            }
          }

          ec.unregisterEventListener(lis);
        }
        break;

      default:
    }
View Full Code Here


   }

   private EventBroadcaster getEventBroadcaster() {

    Context ctx = getContext();
    EventCentral evc = (EventCentral) ctx.get("EventCentral");
    if (evc == ec) {
      return eb;
    }

    synchronized(this) {
View Full Code Here

      log.debug("done");
      return;
    }


    EventCentral ec = null;

    if (name != null) {
      RegistryContext ctx = new RegistryContext();
      try {
         ec = (EventCentral) ctx.lookup(name);
      } catch(ClassCastException ex) {
        error("Object bound in registry under " + name + " is not a valid EventCentral object: " + ctx.lookup(name));
        return;
      } catch(NamingException ex) {
        log.error("Failed to retrieve EventCentral: ", ex);
        error("Failed to find EventCentral with registry name: " + name);
        return;
      }
    } else {
      Context ctx = getShell().getContext();
      ec = (EventCentral) ctx.get("EventCentral");
    }

    if(ec == null) {
      error("Failed to locate EventCentral (make sure you specify EventCentral lookup name, or make sure instance is available in shell context under 'EventCentral')");
      return;
    }


    if(ll) {

      Map listeners = ec.getListeners(all);

      Iterator it = listeners.entrySet().iterator();
      while(it.hasNext()) {
        Map.Entry ent = (Map.Entry) it.next();

        EventCentral.ListenerData ldat = (EventCentral.ListenerData) ent.getValue();
        out.println(ent.getKey() + ": " + ldat.getFilter() + " - " + ldat.getListener());
      }
    } else if(lb) {
      Map broadcasters = ec.getBroadcasters(all);

      Iterator it = broadcasters.entrySet().iterator();
      while(it.hasNext()) {
        Map.Entry ent = (Map.Entry) it.next();
        out.println(ent.getKey() + ": " + ent.getValue());
View Full Code Here

    // get ref to EventCentral
    Context ctx = getShell().getContext();

    // we could also specify lookup name on cmdline or as ENV variable
    EventCentral ec = (EventCentral) ctx.get("EventCentral");

    if(ec == null) {
      error(new org.jboss.fresh.shell.UninitializedEnvironmentException("EventCentral not bound in context"));
      return;
    }

    log.info("EC1 Listeners: " + ec.getListeners());
    log.info("EC1 Broadcasters: " + ec.getBroadcasters());

    // lookup EventNetRouter for our name
    EventNetRouter router = ec.getEventNetRouter(initorID);

//    Thread t = null;

log.info("=== processid: " + getProcess().getID());
    // if exists take over : tell it to stop, get Connector from it and set Buffers on it, then tell EventNetRouter to start
View Full Code Here

TOP

Related Classes of org.jboss.fresh.events.EventCentral

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.