Пример #1
0
  @Test
  public final void testInstantiation() throws Throwable {
    Iterable<ServiceReference<JettyService>> services = module.findServices(JettyService.class);
    assertNotNull(services);

    Iterator<ServiceReference<JettyService>> iterator = services.iterator();
    assertTrue(iterator.hasNext());

    ServiceReference<JettyService> serviceRef = iterator.next();
    assertNotNull(serviceRef);

    JettyService jettyService = serviceRef.get();
    assertNotNull(jettyService);

    String output =
        defaultHttpClient.execute(
            new HttpGet("http://127.0.0.1:8041/helloWorld"), stringResponseHandler);
    assertEquals("Hello World", output);
  }
Пример #2
0
 @Override
 public void beforePassivation(ServiceReference<EventStoreActivation> passivating)
     throws Exception {
   passivating.get().passivateEventStore();
 }
Пример #3
0
 @Override
 public void afterActivation(ServiceReference<EventStoreActivation> activated) throws Exception {
   activated.get().activateEventStore();
 }
Пример #4
0
 @Override
 public void afterActivation(ServiceReference<BootstrapData> activated) throws Exception {
   activated.get().insertInitialData();
 }
Пример #5
0
 private AlarmPoint createAlarm(String name) {
   ServiceReference<AlarmSystem> ref = module.findService(AlarmSystem.class);
   alarmSystem = ref.get();
   return alarmSystem.createAlarm(name, createCategory("AlarmHistoryTest"));
 }
  public void init(
      @Service @IdentifiedBy("testds") DataSource dataSource,
      @Service @IdentifiedBy("testds2") ServiceReference<DataSource> dataSource2)
      throws SQLException, PropertyVetoException {
    Databases databases = new Databases(dataSource);

    // Insert some data and print it out
    databases.update("insert into test values ('id1','foo')");
    databases
        .query("select * from test")
        .transferTo(
            Outputs.withReceiver(
                new Receiver<ResultSet, SQLException>() {
                  @Override
                  public void receive(ResultSet item) throws SQLException {
                    System.out.println(item.getString("id"));
                  }
                }));

    Databases databases2 = new Databases(dataSource2.get());

    // Insert some data and print it out
    databases2.update("insert into test values ('id2','bar')");
    databases2
        .query("select * from test")
        .transferTo(
            Outputs.withReceiver(
                new Receiver<ResultSet, SQLException>() {
                  @Override
                  public void receive(ResultSet item) throws SQLException {
                    System.out.println(item.getString("id"));
                  }
                }));

    // Trip the CB
    dataSource2.metaInfo(CircuitBreaker.class).trip();

    // This should now fail
    try {
      databases2
          .query("select * from test")
          .transferTo(
              Outputs.withReceiver(
                  new Receiver<ResultSet, SQLException>() {
                    @Override
                    public void receive(ResultSet item) throws SQLException {
                      System.out.println(item.getString("id"));
                    }
                  }));

      Assert.fail();

    } catch (Throwable e) {
      // Correct
    }

    // Turn the CB back on
    dataSource2.metaInfo(CircuitBreaker.class).turnOn();

    // This should now work
    databases2
        .query("select * from test")
        .transferTo(
            Outputs.withReceiver(
                new Receiver<ResultSet, SQLException>() {
                  @Override
                  public void receive(ResultSet item) throws SQLException {
                    System.out.println(item.getString("id"));
                  }
                }));
  }
 @Override
 public void beforePassivation(ServiceReference<ApplicationManagerService> passivating)
     throws Exception {
   passivating.get().unexportApplicationStructure();
 }
 @Override
 public void afterActivation(ServiceReference<ApplicationManagerService> activated)
     throws Exception {
   activated.get().exportApplicationStructure();
 }
 public boolean isAvailable() {
   Class<?> mainType = first(serviceDescriptor.types());
   ServiceReference<?> first =
       first(filter(withId(serviceDescriptor.identity()), module.findServices(mainType)));
   return first != null && first.isAvailable();
 }
 public void activate() throws Exception {
   for (ServiceReference<ServiceCircuitBreaker> circuitBreaker : circuitBreakers) {
     registerCircuitBreaker(circuitBreaker.get().getCircuitBreaker(), circuitBreaker.identity());
   }
 }