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
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
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(java.lang.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
  2. The service must be registered with a service property (defined in the 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.

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 service property for service selection.
     public RequestLogServiceFacade(BundleContext contextString serviceName) {
         String filter = "(&(" + . + "=" + RequestLog.class.getName() + ")("
             + . + "=" + serviceName + "))";
         this. = new ServiceTracker(contextfilternull);;
         // use negative initial tracking count to force acquiry of services
         this. = -1;

     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++) {
     public void close() {
        // drop the service references and reinitialize tracking counter
        this. = null;
        this. = -1;
        // terminate using the RequestLog service(s)
New to GrepCode? Check out our FAQ X