repository event support for new event system

This commit is contained in:
Sebastian Sdorra
2012-12-08 14:53:35 +01:00
parent 422a753ac6
commit b7efb30419
2 changed files with 134 additions and 12 deletions

View File

@@ -39,6 +39,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.HandlerEvent;
import sonia.scm.event.ScmEventBus;
import sonia.scm.util.AssertUtil;
import sonia.scm.util.Util;
@@ -53,6 +54,9 @@ import java.util.Map;
import java.util.Set;
/**
* Abstract base class for {@link RepositoryManager} implementations. This class
* implements the listener and hook methods of the {@link RepositoryManager}
* interface.
*
* @author Sebastian Sdorra
*/
@@ -73,7 +77,7 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
* @param event
*/
protected abstract void fireHookEvent(RepositoryHook hook,
RepositoryHookEvent event);
RepositoryHookEvent event);
/**
* Method description
@@ -131,10 +135,10 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
}
/**
* Method description
* Register a {@link RepositoryListener}.
*
*
* @param listener
* @param listener {@link RepositoryListener} to register
*/
@Override
public void addListener(RepositoryListener listener)
@@ -143,10 +147,10 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
}
/**
* Method description
* Register a {@link java.util.Collection} of {@link RepositoryListener}s.
*
*
* @param listeners
* @param listeners listeners to register
*/
@Override
public void addListeners(Collection<RepositoryListener> listeners)
@@ -206,10 +210,10 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
}
/**
* Method description
* Remove specified {@link RepositoryListener}.
*
*
* @param listener
* @param listener to remove
*/
@Override
public void removeListener(RepositoryListener listener)
@@ -218,11 +222,12 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
}
/**
* Method description
* Calls the {@link RepositoryListener#onEvent(Repository,sonia.scm.HandlerEvent)}
* method of all registered listeners and send a {@link RepositoryEvent} to
* the {@link ScmEventBus}.
*
*
* @param repository
* @param event
* @param repository repository that has changed
* @param event type of change event
*/
protected void fireEvent(Repository repository, HandlerEvent event)
{
@@ -230,6 +235,8 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
{
listener.onEvent(repository, event);
}
ScmEventBus.getInstance().post(new RepositoryEvent(repository, event));
}
//~--- fields ---------------------------------------------------------------
@@ -237,7 +244,7 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
/** Field description */
private Map<RepositoryHookType, List<RepositoryHook>> hookMap =
new EnumMap<RepositoryHookType,
List<RepositoryHook>>(RepositoryHookType.class);
List<RepositoryHook>>(RepositoryHookType.class);
/** Field description */
private Set<RepositoryListener> listenerSet =

View File

@@ -0,0 +1,115 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Objects;
import sonia.scm.HandlerEvent;
import sonia.scm.event.HandlerEventBase;
/**
* The RepositoryEvent is fired if a group object changes.
*
* @author Sebastian Sdorra
* @since 1.23
*/
public final class RepositoryEvent implements HandlerEventBase<Repository>
{
/**
* Constructs new repository event
*
*
* @param repository changed repository
* @param eventType type of the event
*/
public RepositoryEvent(Repository repository, HandlerEvent eventType)
{
this.repository = repository;
this.eventType = eventType;
}
//~--- methods --------------------------------------------------------------
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public String toString()
{
//J-
return Objects.toStringHelper(this)
.add("eventType", eventType)
.add("repository", repository)
.toString();
//J+
}
//~--- get methods ----------------------------------------------------------
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public HandlerEvent getEventType()
{
return eventType;
}
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public Repository getItem()
{
return repository;
}
//~--- fields ---------------------------------------------------------------
/** event type */
private HandlerEvent eventType;
/** changed repository */
private Repository repository;
}