org.apache.maven.wagon.events.TransferEventSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-realer Show documentation
Show all versions of virtdata-lib-realer Show documentation
With inspiration from other libraries
package org.apache.maven.wagon.events;
/*
* 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.
*/
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* The class allows registration and removal of event listeners of type
* TransferListener and dispatch of those events to those listeners
*
* @author Michal Maczka
* @version $Id: TransferEventSupport.java 682051 2008-08-02 21:29:38Z hboutemy $
*/
public final class TransferEventSupport
{
/**
* registered listeners
*/
private final List listeners = new ArrayList();
/**
* Adds the listener to the collection of listeners
* who will be notified when any transfer event occurs
* in this Wagon
object.
*
* If listener is null
, no exception is thrown and no action is performed
*
* @param listener the transfer listener
* @see #removeTransferListener(org.apache.maven.wagon.events.TransferListener)
* @see TransferListener
*/
public synchronized void addTransferListener( final TransferListener listener )
{
if ( listener != null )
{
listeners.add( listener );
}
}
/**
* Removes the transfer listener from the collection of listeners so
* it no longer receives transfer events.
*
* If listener is null
or specified listener was not added
* to this TransferEventSupport
object
* no exception is thrown and no action is performed
*
* @param listener the transfer listener
* @see #addTransferListener(TransferListener)
*/
public synchronized void removeTransferListener( final TransferListener listener )
{
listeners.remove( listener );
}
/**
* Returns whether the specified instance of transfer
* listener was added to the collection of listeners
* who will be notified when an transfer event occurs
*
* @param listener the transfer listener
* @return true
* if given listener was added to the collection of listeners
* false
otherwise
* @see org.apache.maven.wagon.events.TransferEvent
* @see #addTransferListener(TransferListener)
*/
public synchronized boolean hasTransferListener( final TransferListener listener )
{
return listeners.contains( listener );
}
/**
* Dispatches the given TransferEvent
* to all registered listeners (calls method {@link TransferListener#transferStarted(TransferEvent)} on all of
* them}. The Event should be of type {@link TransferEvent#TRANSFER_COMPLETED}
*
* @param transferEvent the TransferEvent which will be dispatched to listeners
*/
public synchronized void fireTransferStarted( final TransferEvent transferEvent )
{
for ( Iterator iter = listeners.iterator(); iter.hasNext(); )
{
final TransferListener listener = (TransferListener) iter.next();
listener.transferStarted( transferEvent );
}
}
/**
* Dispatches the given TransferEvent
* to all registered listeners (calls method {@link TransferListener#transferProgress(TransferEvent, byte[], int)}
* on all of them). The Event should be of type {@link TransferEvent#TRANSFER_PROGRESS}.
*
* @param transferEvent the TransferEvent which will be dispatched to listeners
* @param buffer the buffer containing the additional content
* @param length the length of the content in the buffer
*/
public synchronized void fireTransferProgress( final TransferEvent transferEvent, byte[] buffer, int length )
{
for ( Iterator iter = listeners.iterator(); iter.hasNext(); )
{
final TransferListener listener = (TransferListener) iter.next();
listener.transferProgress( transferEvent, buffer, length );
}
}
/**
* Dispatches the given TransferEvent
* to all registered listeners (calls method {@link TransferListener#transferCompleted(TransferEvent)} on all of
* them}. The Event should be of type {@link TransferEvent#TRANSFER_COMPLETED}
*
* @param transferEvent the TransferEvent which will be dispatched to listeners
*/
public synchronized void fireTransferCompleted( final TransferEvent transferEvent )
{
for ( Iterator iter = listeners.iterator(); iter.hasNext(); )
{
final TransferListener listener = (TransferListener) iter.next();
listener.transferCompleted( transferEvent );
}
}
/**
* Dispatches the given TransferEvent
* to all registered listeners (calls method {@link TransferListener#transferError(TransferEvent)} on all of them.
* The Event should be of type {@link TransferEvent#TRANSFER_ERROR} and it is expected that
* {@link TransferEvent#getException()} } method will return not null value
*
* @param transferEvent the TransferEvent which will be dispatched to listeners
*/
public synchronized void fireTransferError( final TransferEvent transferEvent )
{
for ( Iterator iter = listeners.iterator(); iter.hasNext(); )
{
final TransferListener listener = (TransferListener) iter.next();
listener.transferError( transferEvent );
}
}
/**
* Dispatches the given debug message
* to all registered listeners (calls method {@link TransferListener#debug(String)} on all of them.
*
* @param message the debug message which will be dispatched to listeners
*/
public synchronized void fireDebug( final String message )
{
for ( Iterator iter = listeners.iterator(); iter.hasNext(); )
{
final TransferListener listener = (TransferListener) iter.next();
listener.debug( message );
}
}
/**
* Dispatches the given TransferEvent
* to all registered listeners (calls method {@link TransferListener#transferInitiated(TransferEvent)} on all of
* them. The Event should be of type {@link TransferEvent#TRANSFER_INITIATED}.
*
* @param transferEvent the TransferEvent which will be dispatched to listeners
*/
public synchronized void fireTransferInitiated( final TransferEvent transferEvent )
{
for ( Iterator iter = listeners.iterator(); iter.hasNext(); )
{
final TransferListener listener = (TransferListener) iter.next();
listener.transferInitiated( transferEvent );
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy