コード例 #1
0
  public static void main(String[] args) throws Exception {
    final int totalServiceDefinitions = Integer.parseInt(args[0]);
    final int threadPoolSize = Integer.parseInt(args[1]);

    final ServiceContainer container = ServiceContainer.Factory.create();
    final ThreadPoolExecutor executor =
        new ThreadPoolExecutor(
            threadPoolSize,
            threadPoolSize,
            1000,
            TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());
    container.setExecutor(executor);

    BatchBuilder batch = container.batchBuilder();

    final LatchedFinishListener listener = new LatchedFinishListener();

    final Value<Field> testFieldValue =
        new CachedValue<Field>(
            new LookupFieldValue(new ImmediateValue<Class<?>>(TestObject.class), "test"));

    final List<Value<Class<?>>> params =
        Collections.singletonList((Value<Class<?>>) new ImmediateValue<Class<?>>(TestObject.class));
    final List<Value<Method>> setterMethodValues = new ArrayList<Value<Method>>(5);
    for (int i = 0; i < 5; i++)
      setterMethodValues.add(
          new CachedValue<Method>(
              new LookupMethodValue(
                  new ImmediateValue<Class<?>>(TestObject.class), "setOther" + (i), params)));

    for (int i = 0; i < totalServiceDefinitions; i++) {
      final TestObject testObject = new TestObject("test" + i);
      final TestObjectService service = new TestObjectService(testObject);
      final ServiceBuilder<TestObject> builder =
          batch.addService(ServiceName.of(("test" + i).intern()), service).addListener(listener);

      final Object injectedValue = new Object();
      //            builder.addInjection(injectedValue).toFieldValue(testFieldValue);

      int nextDivByFive = (5 - (i % 5)) + i;
      int numDeps = Math.min(nextDivByFive - i, totalServiceDefinitions - i - 1);
      for (int j = 0; j < numDeps; j++) {
        int depId = i + j + 1;
        if (depId % 5 == 0) continue;

        //                builder.addDependency(ServiceName.of(("test" +
        // depId).intern())).toMethodValue(setterMethodValues.get(j),
        // Collections.singletonList(Values.injectedValue()));
      }
    }

    batch.install();
    listener.await();
    System.out.println(totalServiceDefinitions + " : " + listener.getElapsedTime() / 1000.0);
    container.shutdown();
    executor.shutdown();
  }
コード例 #2
0
ファイル: LoggerAdd.java プロジェクト: jdmr/jboss-as
 /** {@inheritDoc} */
 protected <P> void applyUpdate(
     UpdateContext updateContext, UpdateResultHandler<? super Void, P> resultHandler, P param) {
   try {
     final String loggerName = getLoggerName();
     final LoggerService service = new LoggerService(loggerName);
     service.setLevel(Level.parse(getLevelName()));
     final BatchBuilder batchBuilder = updateContext.getBatchBuilder();
     final BatchServiceBuilder<Logger> builder =
         batchBuilder.addService(LogServices.loggerName(loggerName), service);
     builder.setInitialMode(ServiceController.Mode.ACTIVE);
     builder.addListener(new UpdateResultHandler.ServiceStartListener<P>(resultHandler, param));
   } catch (Throwable t) {
     resultHandler.handleFailure(t, param);
     return;
   }
 }
コード例 #3
0
 public static void addService(BatchBuilder batchBuilder, String contextName, Deployment dep) {
   DeploymentHolderService service = new DeploymentHolderService(dep);
   ServiceBuilder<Deployment> serviceBuilder =
       batchBuilder.addService(getServiceName(contextName), service);
   serviceBuilder.addDependency(
       BundleManagerService.SERVICE_NAME, BundleManager.class, service.injectedBundleManager);
   serviceBuilder.setInitialMode(Mode.ACTIVE);
   serviceBuilder.install();
 }
コード例 #4
0
 public static void addService(
     BatchBuilder batchBuilder, Deployment deployment, String contextName) {
   ModuleRegistrationService service = new ModuleRegistrationService(deployment);
   ServiceBuilder<Deployment> serviceBuilder =
       batchBuilder.addService(getServiceName(contextName), service);
   serviceBuilder.addDependency(
       BundleManagerService.SERVICE_NAME, BundleManager.class, service.injectedBundleManager);
   serviceBuilder.addDependency(PackageAdminService.SERVICE_NAME);
   serviceBuilder.addDependency(Services.deploymentUnitName(contextName));
   serviceBuilder.setInitialMode(Mode.ACTIVE);
   serviceBuilder.install();
 }
コード例 #5
0
  @Override
  @SuppressWarnings({"rawtypes", "unchecked"})
  public ServiceState registerService(
      AbstractBundle bundleState, String[] clazzes, Object serviceValue, Dictionary properties) {
    if (clazzes == null || clazzes.length == 0)
      throw new IllegalArgumentException("Null service classes");

    // Immediately after registration of a {@link ListenerHook}, the ListenerHook.added() method
    // will be called
    // to provide the current collection of service listeners which had been added prior to the hook
    // being registered.
    Collection<ListenerInfo> listenerInfos = null;
    if (serviceValue instanceof ListenerHook)
      listenerInfos = eventsPlugin.getServiceListenerInfos(null);

    // A temporary association of the clazz and name
    Map<ServiceName, String> associations = new HashMap<ServiceName, String>();

    // Generate the service names
    long serviceId = getNextServiceId();
    ServiceName[] serviceNames = new ServiceName[clazzes.length];
    for (int i = 0; i < clazzes.length; i++) {
      if (clazzes[i] == null)
        throw new IllegalArgumentException("Null service class at index: " + i);

      String shortName = clazzes[i].substring(clazzes[i].lastIndexOf(".") + 1);
      serviceNames[i] =
          ServiceName.of(
              "jbosgi", bundleState.getSymbolicName(), shortName, new Long(serviceId).toString());
    }

    final ServiceState serviceState =
        new ServiceState(bundleState, serviceId, serviceNames, clazzes, serviceValue, properties);
    BatchBuilder batchBuilder = serviceContainer.batchBuilder();
    Service service =
        new Service() {
          @Override
          public Object getValue() throws IllegalStateException {
            // [TODO] for injection to work this needs to be the Object value
            return serviceState;
          }

          @Override
          public void start(StartContext context) throws StartException {}

          @Override
          public void stop(StopContext context) {}
        };

    log.debug("Register service: " + Arrays.asList(serviceNames));

    ServiceName rootServiceName = serviceNames[0];
    BatchServiceBuilder serviceBuilder = batchBuilder.addService(rootServiceName, service);
    associations.put(rootServiceName, clazzes[0]);

    // Set the startup mode
    serviceBuilder.setInitialMode(Mode.AUTOMATIC);

    // Add the service aliases
    for (int i = 1; i < serviceNames.length; i++) {
      ServiceName alias = serviceNames[i];
      associations.put(alias, clazzes[1]);
      serviceBuilder.addAliases(alias);
    }

    try {
      batchBuilder.install();

      // Register the name association. We do this here
      // in case anything went wrong during the install
      for (Entry<ServiceName, String> aux : associations.entrySet()) {
        bundleState.addRegisteredService(serviceState);
        registerNameAssociation(aux.getValue(), aux.getKey());
      }
    } catch (ServiceRegistryException ex) {
      log.error("Cannot register services: " + serviceNames, ex);
    }

    // Call the newly added ListenerHook.added() method
    if (serviceValue instanceof ListenerHook) {
      ListenerHook listenerHook = (ListenerHook) serviceValue;
      listenerHook.added(listenerInfos);
    }

    // This event is synchronously delivered after the service has been registered with the
    // Framework.
    eventsPlugin.fireServiceEvent(bundleState, ServiceEvent.REGISTERED, serviceState);

    return serviceState;
  }
コード例 #6
0
 @Override
 public BatchBuilder addDependency(ServiceName... dependencies) {
   delegate.addDependency(dependencies);
   return this;
 }
コード例 #7
0
 @Override
 public BatchBuilder addListener(Collection<ServiceListener<Object>> listeners) {
   delegate.addListener(listeners);
   return this;
 }
コード例 #8
0
 @Override
 public BatchBuilder addListener(ServiceListener<Object>... listeners) {
   delegate.addListener(listeners);
   return this;
 }
コード例 #9
0
 @Override
 public <T> BatchServiceBuilder<T> addServiceValueIfNotExist(
     ServiceName name, Value<? extends Service<T>> value) throws IllegalArgumentException {
   return new ServerStartBatchServiceBuilder<T>(
       name, delegate.addServiceValueIfNotExist(name, value));
 }
コード例 #10
0
 @Override
 public <T> BatchServiceBuilder<T> addService(ServiceName name, Service<T> service)
     throws IllegalArgumentException {
   return new ServerStartBatchServiceBuilder<T>(name, delegate.addService(name, service));
 }
コード例 #11
0
 @Override
 public BatchBuilder subBatchBuilder() {
   return new ServerStartBatchBuilder(delegate.subBatchBuilder(), serverStartupListener);
 }
コード例 #12
0
 @Override
 public void install() throws ServiceRegistryException {
   delegate.install();
 }
コード例 #13
0
 @Override
 public BatchBuilder addDependency(Collection<ServiceName> dependencies) {
   delegate.addDependency(dependencies);
   return this;
 }
コード例 #14
0
  protected void processDeployment(
      final String hostName, final WarMetaData warMetaData, final DeploymentUnitContext context)
      throws DeploymentUnitProcessingException {
    final VirtualFile deploymentRoot = VirtualFileAttachment.getVirtualFileAttachment(context);
    final Module module = context.getAttachment(ModuleDeploymentProcessor.MODULE_ATTACHMENT_KEY);
    if (module == null) {
      throw new DeploymentUnitProcessingException(
          "failed to resolve module for deployment " + deploymentRoot);
    }
    final ClassLoader classLoader = module.getClassLoader();
    final JBossWebMetaData metaData = warMetaData.getMergedJBossWebMetaData();

    // Create the context
    final StandardContext webContext = new StandardContext();
    final ContextConfig config = new JBossContextConfig(context);
    // Set the deployment root
    try {
      webContext.setDocBase(deploymentRoot.getPhysicalFile().getAbsolutePath());
    } catch (IOException e) {
      throw new DeploymentUnitProcessingException(e);
    }
    webContext.addLifecycleListener(config);

    // Set the path name
    final String deploymentName = context.getName();
    String pathName = null;
    if (metaData.getContextRoot() == null) {
      pathName = deploymentRoot.getName();
      if (pathName.equals("ROOT.war")) {
        pathName = "";
      } else {
        pathName = "/" + pathName.substring(0, pathName.length() - 4);
      }
    } else {
      pathName = metaData.getContextRoot();
      if ("/".equals(pathName)) {
        pathName = "";
      }
    }
    webContext.setPath(pathName);
    webContext.setIgnoreAnnotations(true);

    // Add a dummy realm for now
    Realm realm = new MemoryRealm();
    webContext.setRealm(realm);

    //
    final Loader loader = new WebCtxLoader(classLoader);
    final InstanceManager manager = new WebInjectionContainer(classLoader);
    webContext.setInstanceManager(manager);
    webContext.setLoader(loader);

    // Set the session cookies flag according to metadata
    switch (metaData.getSessionCookies()) {
      case JBossWebMetaData.SESSION_COOKIES_ENABLED:
        webContext.setCookies(true);
        break;
      case JBossWebMetaData.SESSION_COOKIES_DISABLED:
        webContext.setCookies(false);
        break;
    }

    String metaDataSecurityDomain = metaData.getSecurityDomain();
    if (metaDataSecurityDomain != null) {
      metaDataSecurityDomain = metaDataSecurityDomain.trim();
    }

    // Add the context service
    final BatchBuilder builder = context.getBatchBuilder();
    builder
        .addService(
            WebSubsystemElement.JBOSS_WEB.append(deploymentName),
            new WebDeploymentService(webContext))
        .addDependency(
            WebSubsystemElement.JBOSS_WEB_HOST.append(hostName),
            Host.class,
            new WebContextInjector(webContext))
        .setInitialMode(Mode.ACTIVE);
  }