コード例 #1
0
  protected void setSubscriptions(Subscriptions eventing) {
    eventing.setImplBean(
        new ISubscriptionsService() {
          private String[] eventNames = null;

          public String subscribe(
              String endpoint, boolean isRestEndpoint, String path, String eventName) {
            SuperTenantCarbonContext.startTenantFlow();
            try {
              SuperTenantCarbonContext.getCurrentContext()
                  .setTenantId(MultitenantConstants.SUPER_TENANT_ID);
              UserRegistry registry =
                  Utils.getRegistryService().getRegistry(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
              if (RegistryUtils.isRegistryReadOnly(registry.getRegistryContext())) {
                return null;
              }

              SubscriptionBean subscriptionBean =
                  SubscriptionBeanPopulator.subscribeAndPopulate(
                      registry, path, endpoint, eventName, isRestEndpoint);
              if (subscriptionBean != null
                  && subscriptionBean.getSubscriptionInstances() != null
                  && subscriptionBean.getSubscriptionInstances().length > 0)
                return subscriptionBean.getSubscriptionInstances()[0].getId();
            } catch (RegistryException e) {
              log.error("An error occurred while subscribing", e);
            } finally {
              SuperTenantCarbonContext.endTenantFlow();
            }
            return "";
          }

          public void unsubscribe(String id) {
            SuperTenantCarbonContext.startTenantFlow();
            try {
              SuperTenantCarbonContext.getCurrentContext()
                  .setTenantId(MultitenantConstants.SUPER_TENANT_ID);
              Utils.getRegistryEventingService().unsubscribe(id);
            } finally {
              SuperTenantCarbonContext.endTenantFlow();
            }
          }

          public String[] getEventNames() {
            if (eventNames != null) {
              return eventNames;
            }
            Set<String> output = new TreeSet<String>();
            Collection values = Utils.getRegistryEventingService().getEventTypes().values();
            for (Object value : values) {
              String[] types = (String[]) value;
              if (types[0] != null) {
                output.add(types[0]);
              }
              if (types[1] != null) {
                output.add(types[1]);
              }
            }
            eventNames = output.toArray(new String[output.size()]);
            return eventNames;
          }

          public String[] getList() {
            List<String> output = new LinkedList<String>();
            SuperTenantCarbonContext.startTenantFlow();
            try {
              SuperTenantCarbonContext.getCurrentContext()
                  .setTenantId(MultitenantConstants.SUPER_TENANT_ID);
              List<Subscription> subscriptions =
                  Utils.getRegistryEventingService().getAllSubscriptions();
              for (Subscription subscription : subscriptions) {
                output.add(
                    subscription.getId()
                        + ":"
                        + subscription.getTopicName()
                        + ":"
                        + subscription.getEventSinkURL());
              }
            } catch (EventBrokerException e) {
              log.error("Unable to retrieve subscriptions", e);
            } finally {
              SuperTenantCarbonContext.endTenantFlow();
            }
            return output.toArray(new String[output.size()]);
          }
        });
  }
コード例 #2
0
 protected void unsetSubscriptions(Subscriptions eventing) {
   eventing.setImplBean(null);
 }