com.microsoft.azure.storage.StorageEventMultiCaster Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-storage Show documentation
Show all versions of azure-storage Show documentation
SDK for Microsoft Azure Storage Clients
/**
* Copyright Microsoft Corporation
*
* Licensed 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 com.microsoft.azure.storage;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Represents a generic event multi-caster that allows event listeners to be dynamically added and removed.
*
* @param
* An object that represents the type of the event.
* @param
* An object that represents the type of the event listener.
*/
public final class StorageEventMultiCaster> {
/**
* Holds the list of listeners.
*/
private final CopyOnWriteArrayList listeners = new CopyOnWriteArrayList();
/**
* Adds a listener to the event chain.
*
* @param listener
* An EventListenerType
object that represents the listener to add.
*/
public void addListener(final EVENT_LISTENER_TYPE listener) {
this.listeners.add(listener);
}
/**
* Fires the event to all subscribed event listeners.
*
* @param event
* An EVENTTYPE
object that represents the event being multi-casted.
*/
public void fireEvent(final EVENT_TYPE event) {
for (final StorageEvent listener : this.listeners) {
listener.eventOccurred(event);
}
}
/**
* Returns a value that indicates whether any event listeners are registered for events.
*
* @return true
if any event listeners are registered; otherwise, false
.
*/
public boolean hasListeners() {
return this.listeners.size() > 0;
}
/**
* Removes an event listener from the event chain.
*
* @param listener
* An EventListenerType
object that represents the listener to remove.
*/
public void removeListener(final EVENT_LISTENER_TYPE listener) {
this.listeners.remove(listener);
}
}