protected void performRuntime(
     OperationContext context,
     ModelNode operation,
     ModelNode model,
     ServiceVerificationHandler verificationHandler,
     List<ServiceController<?>> newControllers)
     throws OperationFailedException {
   final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
   final String name = address.getLastElement().getValue();
   final ServiceTarget serviceTarget = context.getServiceTarget();
   try {
     final PeriodicRotatingFileHandlerService service = new PeriodicRotatingFileHandlerService();
     final ServiceBuilder<Handler> serviceBuilder =
         serviceTarget.addService(LogServices.handlerName(name), service);
     if (operation.hasDefined(FILE)) {
       final HandlerFileService fileService =
           new HandlerFileService(operation.get(FILE, PATH).asString());
       final ServiceBuilder<?> fileBuilder =
           serviceTarget.addService(LogServices.handlerFileName(name), fileService);
       if (operation.get(FILE).hasDefined(CommonAttributes.RELATIVE_TO)) {
         fileBuilder.addDependency(
             AbstractPathService.pathNameOf(operation.get(FILE, RELATIVE_TO).asString()),
             String.class,
             fileService.getRelativeToInjector());
       }
       fileBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
       serviceBuilder.addDependency(
           LogServices.handlerFileName(name), String.class, service.getFileNameInjector());
     }
     service.setLevel(Level.parse(operation.get(LEVEL).asString()));
     final Boolean autoFlush = operation.get(AUTOFLUSH).asBoolean();
     if (autoFlush != null) service.setAutoflush(autoFlush.booleanValue());
     if (operation.hasDefined(SUFFIX)) service.setSuffix(operation.get(SUFFIX).asString());
     if (operation.hasDefined(ENCODING)) service.setEncoding(operation.get(ENCODING).asString());
     if (operation.hasDefined(FORMATTER)) service.setFormatterSpec(createFormatterSpec(operation));
     serviceBuilder.addListener(verificationHandler);
     serviceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
     newControllers.add(serviceBuilder.install());
   } catch (Throwable t) {
     throw new OperationFailedException(new ModelNode().set(t.getLocalizedMessage()));
   }
 }
Beispiel #2
0
 /** {@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;
   }
 }