All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.xbean.kernel.standard.AsyncServiceMonitor Maven / Gradle / Ivy

The newest version!
/**
 * 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.xbean.kernel.standard;

import java.util.concurrent.Executor;
import org.apache.xbean.kernel.ServiceEvent;
import org.apache.xbean.kernel.ServiceMonitor;

/**
 * The AsyncServiceMonitor delivers service events to a delegate ServiceMonitor asynchronously using an executor.
 *
 * @author Dain Sundstrom
 * @version $Id$
 * @since 2.0
 */
public class AsyncServiceMonitor implements ServiceMonitor {
    private final ServiceMonitor delegate;
    private final Executor executor;

    /**
     * Creates a AsyncServiceMonitor which asynchronously delivers service events to specified delegate
     * ServiceMonitor using the specified executor.
     *
     * @param delegate the service monitor that should recieve the asynchronous events
     * @param executor the executor used to asynchronously deliver the events
     */
    public AsyncServiceMonitor(ServiceMonitor delegate, Executor executor) {
        this.delegate = delegate;
        this.executor = executor;
    }

    /**
     * {@inheritDoc}
     */
    public void serviceRegistered(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceRegistered(serviceEvent);
            }
        });
    }

    /**
     * {@inheritDoc}
     */
    public void serviceStarting(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceStarting(serviceEvent);
            }
        });
    }

    /**
     * {@inheritDoc}
     */
    public void serviceWaitingToStart(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceWaitingToStart(serviceEvent);
            }
        });
    }

    /**
     * {@inheritDoc}
     */
    public void serviceStartError(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceStartError(serviceEvent);
            }
        });
    }

    /**
     * {@inheritDoc}
     */
    public void serviceRunning(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceRunning(serviceEvent);
            }
        });
    }

    /**
     * {@inheritDoc}
     */
    public void serviceStopping(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceStopping(serviceEvent);
            }
        });
    }

    /**
     * {@inheritDoc}
     */
    public void serviceWaitingToStop(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceWaitingToStop(serviceEvent);
            }
        });
    }

    /**
     * {@inheritDoc}
     */
    public void serviceStopError(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceStopError(serviceEvent);
            }
        });
    }

    /**
     * {@inheritDoc}
     */
    public void serviceStopped(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceStopped(serviceEvent);
            }
        });
    }

    /**
     * {@inheritDoc}
     */
    public void serviceUnregistered(final ServiceEvent serviceEvent) {
        executor.execute(new Runnable() {
            public void run() {
                delegate.serviceUnregistered(serviceEvent);
            }
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy