Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 package org.apache.sling.engine.impl.log;
 
 import  org.osgi.framework.BundleContext;
 import  org.osgi.framework.Constants;
The RequestLogServiceFacade is a RequestLog implementation used to redirect output requests to RequestLog services registered with a specific logger name. Each service thus registered is called with the message by the write(String) method.

This class is initialized with the service name which is used to find request log services to send log messages to. Such services are selected as follows:

  1. The service must be registered with service interface org.apache.sling.engine.RequestLog.
  2. The service must be registered with a service property requestlog.name (defined in the RequestLog.REQUEST_LOG_NAME constant whose value (or one of its values, if multi-valued) must be the service name.
 
 class RequestLogServiceFacade implements RequestLog {
 
     // The service tracker used to access the service(s)
     private final ServiceTracker requestLogTracker;
 
     // private copy of services currently available. We cache them to gain some
     // milliseconds, as each call to ServiceTracker.getServices() looks the
     // services up in the service registry
     private Object[] loggers;
 
     // tracking count of the time when we got the service list, if the
     // service tracker changes its count, we have to reaquire the services
     private int trackingCount;

    
Creates an instance of this facade class calling request log services with the given serviceName.

Parameters:
context The BundleContext used to acquire the request log services.
serviceName The name of the services used for logging. This value is used to check the RequestLog.REQUEST_LOG_NAME service property for service selection.
 
     public RequestLogServiceFacade(BundleContext contextString serviceName) {
         String filter = "(&(" + Constants.OBJECTCLASS + "=" + RequestLog.class.getName() + ")("
             + . + "=" + serviceName + "))";
         this. = new ServiceTracker(contextfilternull);
         this..open();
 
         // use negative initial tracking count to force acquiry of services
         this. = -1;
     }

    

See also:
org.apache.sling.engine.RequestLog.write(java.lang.String)
 
     public void write(String message) {
 
         // acquire the current logger list
         Object[] tmpLoggers = this.;
 
         // if services have been added/removed reacquire from the tracker
         if (this. != this..getTrackingCount()) {
             tmpLoggers = this..getServices();
             this. = tmpLoggers;
         }
 
         // finally call the loggers with the message
         if (tmpLoggers != null) {
             for (int i = 0; i < tmpLoggers.lengthi++) {
                 ((RequestLogtmpLoggers[i]).write(message);
             }
         }
     }
 
     public void close() {
        // drop the service references and reinitialize tracking counter
        this. = null;
        this. = -1;
        // terminate using the RequestLog service(s)
        this..close();
    }
New to GrepCode? Check out our FAQ X