Package org.osgi.service.event

Examples of org.osgi.service.event.Event


                  .println(getName()
                           + " sending a synchronus event with message:"
                           + message.toString()
                           + "and the topic:" + topicToSend);
                eventAdmin
                  .sendEvent(new Event(topicToSend, message));
                /* Puts the thread to sleep for 10 seconds */
                i++;
                Thread.sleep(10000);
              } catch (InterruptedException e) {
                //ignored, treated by while loop
              }
            }
          }
        };

      synchDeliver.start();

      asynchDeliver = new Thread() {
          public void run() {
            int i = 0;
            while (!stopped && !Thread.interrupted()) {
              try {
                /* a Hash table to store message in */
                Dictionary message = new Hashtable();
                /* put some properties into the messages */
                message.put("Asynchronus message", new Integer(i));
                /* send the message */
                System.out
                  .println(getName()
                           + " sending a asynchronus event with message:"
                           + message.toString()
                           + "and the topic:" + topicToSend);
                eventAdmin
                  .sendEvent(new Event(topicToSend, message));
                /* Puts the thread to sleep for 10 seconds */
                i++;
                Thread.sleep(10000);
              } catch (InterruptedException e) {
                //ignored, treated by while loop
View Full Code Here


        message.put("Synchronus message",new Integer(i));
        /* test print out */
        System.out.println(getName() + " sending a Synchronus event with message:" +
                           message.toString() + "and the topic:" + topicToSend);
        /* send the message */
        eventAdmin.sendEvent(new Event(topicToSend, message));
      }


      /* a Hash table to store message in */
      message = new Hashtable();
      for(int j = 0; j < propertiesToSend.length;  j += 2) {
        /*fill the propstable*/
        System.out.println("Adding the following to the propsTable:" + propertiesToSend[j] + " and " + propertiesToSend[j+1]);
        message.put(propertiesToSend[j], propertiesToSend[j+1]);
      }

      for (int i = 0; i < messageTosend; i++) {
        message.put("Asynchronus message",new Integer(i));
        /* test print out */
        System.out.println(getName() + " sending an Asynchronus event with message:" +
                           message.toString() + "and the topic:" + topicToSend);
        /* send the message */
        eventAdmin.sendEvent(new Event(topicToSend, message));
      }

    }
View Full Code Here


        if (publisherId <= 2) {
          /* send the message */
          eventAdmin
            .sendEvent(new Event(topicToPublish, message));
        } else if (publisherId > 2) {
          /* send the message */
          eventAdmin
            .postEvent(new Event(topicToPublish, message));

        }

        i++;

View Full Code Here

              /* a Hash table to store message in */
              Dictionary message = new Hashtable();
              /* put some properties into the messages */
              message.put("Synchronus message",new Integer(i));
              /* send the message */
              eventAdmin.sendEvent(new Event("com/acme/timer", message));

            }
          }


        };

      /* print that the test has started */
      System.out.println("Testing synchronus delivery");
      /* start the thread */
      synchDeliver.start();

      /* wait until thread is dead */
      synchDeliver.join();

      Thread asynchDeliver = new Thread() {
          public void run() {

            for (int i = 0; i < messageTosend; i++) {
              /* create the hasht table */
              Dictionary message = new Hashtable();
              /* create the message */
              message.put("Asynchronus message",new Integer(i));
              /* Sends a synchronous event to the admin */
              eventAdmin.postEvent(new Event("com/acme/timer", message));

            }
          }


View Full Code Here

              /* send the message */
              System.out.println(getName()
                                 + " sending a synchronus event with message:"
                                 + message.toString() + "and the topic:"
                                 + topicToSend);
              eventAdmin.sendEvent(new Event(topicToSend, message));
            }
          }
        };

      synchDeliver.start();
      synchDeliver.join();

      Thread asynchDeliver = new Thread() {
          public void run() {

            for (int i = 0; i < messageTosend; i++) {
              /* create the hasht table */
              Dictionary message = new Hashtable();
              /* create the message */
              message.put("Asynchronus message", new Integer(i));
              /* Sends a synchronous event to the admin */
              System.out.println(getName()
                                 + " sending an Asynchronus event with message:"
                                 + message.toString() + "and the topic:"
                                 + topicToSend);
              eventAdmin.postEvent(new Event(topicToSend, message));
            }
          }
        };
      asynchDeliver.start();
      asynchDeliver.join();
View Full Code Here

        /* put the sender */
        message.put("FROM",this);

        if(publisherId>5) {
          /* send the message */
          eventAdmin.sendEvent(new Event(topicToPublish, message));
        } else {
          /* send the message */
          eventAdmin.postEvent(new Event(topicToPublish, message));
        }

        i++;

      }
View Full Code Here

    public EventUtilTest() {
        this.context = new JUnit4Mockery();
    }

    @Test public void testDistributeFlag() {
        final Event distributableEvent = EventUtil.createDistributableEvent("some/topic", null);
        assertTrue(EventUtil.shouldDistribute(distributableEvent));
        final Event nonDistributableEvent = new Event("another/topic", (Dictionary<String, Object>)null);
        assertFalse(EventUtil.shouldDistribute(nonDistributableEvent));
        final Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put("a", "a");
        props.put("b", "b");
        final Event distributableEvent2 = EventUtil.createDistributableEvent("some/topic", props);
        assertTrue(EventUtil.shouldDistribute(distributableEvent2));
        // we should have four properties: 2 custom, one for the dist flag and the fourth for the topic
        assertEquals(4, distributableEvent2.getPropertyNames().length);
        assertEquals("a", distributableEvent2.getProperty("a"));
        assertEquals("b", distributableEvent2.getProperty("b"));
    }
View Full Code Here

        assertEquals("a", distributableEvent2.getProperty("a"));
        assertEquals("b", distributableEvent2.getProperty("b"));
    }

    @Test public void testLocalFlag() {
        final Event localEvent = new Event("local/event", (Dictionary<String, Object>)null);
        assertTrue(EventUtil.isLocal(localEvent));
        final Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(EventUtil.PROPERTY_APPLICATION, "application1");
        final Event remoteEvent = new Event("remote/event", props);
        assertFalse(EventUtil.isLocal(remoteEvent));
    }
View Full Code Here

                // should never happen
                throw new Error(t);
            }
        } finally {
            props.put(CommandExecutionProperties.TIMESTAMP_END, System.currentTimeMillis());
            Event event = new Event(CommandExecutionProperties.REPOSITORY_TOPIC, props);
            eventAdmin.postEvent(event);
        }
    }
View Full Code Here

        properties.put(SlingConstants.PROPERTY_USERID, authInfo.getUser());
        properties.put(AuthenticationInfo.AUTH_TYPE, authInfo.getAuthType());

        EventAdmin localEA = this.eventAdmin;
        if (localEA != null) {
            localEA.postEvent(new Event(AuthConstants.TOPIC_LOGIN, properties));
        }
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.event.Event

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.