remove old hook system in favor of event bus

This commit is contained in:
Sebastian Sdorra
2014-01-03 16:32:48 +01:00
parent 0fdc458b9f
commit dc19da4a76
18 changed files with 103 additions and 1433 deletions

View File

@@ -1,74 +0,0 @@
/**
* 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;
/**
*
* @author Sebastian Sdorra
* @since 1.6
*/
public abstract class AbstractRepositoryHookEvent implements RepositoryHookEvent
{
/**
* Method description
*
*
* @return
*/
@Override
public Repository getRepository()
{
return repository;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repository
*/
@Override
public void setRepository(Repository repository)
{
this.repository = repository;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Repository repository;
}

View File

@@ -43,14 +43,6 @@ import org.slf4j.LoggerFactory;
import sonia.scm.HandlerEvent;
import sonia.scm.event.ScmEventBus;
import sonia.scm.util.AssertUtil;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Abstract base class for {@link RepositoryManager} implementations. This class
@@ -68,130 +60,24 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
//~--- methods --------------------------------------------------------------
/**
* Sends a {@link RepositoryHookEvent} to the specified
* {@link RepositoryHook}.
*
*
* @param hook receiving repository hook
* @param event hook event
*/
protected abstract void fireHookEvent(RepositoryHook hook,
RepositoryHookEvent event);
/**
* Registers a {@link RepositoryHook}
*
*
* @param hook hook to register
*/
@Override
public void addHook(RepositoryHook hook)
{
Collection<RepositoryHookType> types = hook.getTypes();
if (types != null)
{
for (RepositoryHookType type : types)
{
if (logger.isDebugEnabled())
{
logger.debug("register {} hook {}", type, hook.getClass());
}
synchronized (AbstractRepositoryManager.class)
{
List<RepositoryHook> hooks = hookMap.get(type);
if (hooks == null)
{
hooks = new ArrayList<RepositoryHook>();
hookMap.put(type, hooks);
}
hooks.add(hook);
}
}
}
else if (logger.isWarnEnabled())
{
logger.warn("could not find any repository type");
}
}
/**
* Register a {@link Collection} of {@link RepositoryHook}s
*
*
* @param hooks hooks to register
*/
@Override
public void addHooks(Collection<RepositoryHook> hooks)
{
for (RepositoryHook hook : hooks)
{
addHook(hook);
}
}
/**
* Sends a {@link RepositoryHookEvent} to each registered
* {@link RepositoryHook} and sends the {@link RepositoryHookEvent} to
* the {@link ScmEventBus}.
*
*
* @param repository changed repository
* @param event event to be fired
*/
@Override
public void fireHookEvent(Repository repository, RepositoryHookEvent event)
public void fireHookEvent(RepositoryHookEvent event)
{
AssertUtil.assertIsNotNull(repository);
AssertUtil.assertIsNotNull(event);
AssertUtil.assertIsNotNull(event.getRepository());
AssertUtil.assertIsNotNull(event.getType());
event.setRepository(repository);
// prepare the event
event = prepareHookEvent(event);
// post wrapped hook to event system
ScmEventBus.getInstance().post(WrappedRepositoryHookEvent.wrap(event));
List<RepositoryHook> hooks = hookMap.get(event.getType());
if (Util.isNotEmpty(hooks))
{
for (RepositoryHook hook : hooks)
{
fireHookEvent(hook, event);
}
}
}
/**
* Method description
*
*
* @param hook
*/
@Override
public void removeHook(RepositoryHook hook)
{
Collection<RepositoryHookType> types = hook.getTypes();
if (types != null)
{
for (RepositoryHookType type : types)
{
List<RepositoryHook> hooks = hookMap.get(type);
if (hooks != null)
{
hooks.remove(hook);
}
}
}
}
/**
@@ -218,10 +104,4 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
{
return event;
}
//~--- fields ---------------------------------------------------------------
/** repository hooks map */
private Map<RepositoryHookType, List<RepositoryHook>> hookMap =
Maps.newEnumMap(RepositoryHookType.class);
}

View File

@@ -35,6 +35,7 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.github.legman.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +52,7 @@ import java.util.Collection;
* @author Sebastian Sdorra
* @since 1.6
*/
public class CacheClearHook implements RepositoryHook
public class CacheClearHook
{
/** the logger for CacheClearHook */
@@ -106,8 +107,8 @@ public class CacheClearHook implements RepositoryHook
*
* @param event
*/
@Override
public void onEvent(RepositoryHookEvent event)
@Subscribe
public void onEvent(PostReceiveRepositoryHookEvent event)
{
if (logger.isDebugEnabled())
{
@@ -122,30 +123,6 @@ public class CacheClearHook implements RepositoryHook
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public Collection<RepositoryHookType> getTypes()
{
return types;
}
/**
* Method description
*
*
* @return
*/
@Override
public boolean isAsync()
{
return true;
}
//~--- methods --------------------------------------------------------------
/**
@@ -166,12 +143,10 @@ public class CacheClearHook implements RepositoryHook
* Method description
*
*
* @param manager
* @param cache
*/
protected void init(RepositoryManager manager, Cache<?, ?> cache)
protected void init(Cache<?, ?> cache)
{
manager.addHook(this);
this.cache = cache;
}
@@ -179,8 +154,4 @@ public class CacheClearHook implements RepositoryHook
/** Field description */
private Cache<?, ?> cache;
/** Field description */
private Collection<RepositoryHookType> types =
Arrays.asList(RepositoryHookType.POST_RECEIVE);
}

View File

@@ -1,135 +0,0 @@
/**
* 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 sonia.scm.repository.api.HookChangesetBuilder;
import sonia.scm.repository.api.HookContext;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
/**
* The {@link ExtendedRepositoryHookEvent} at the possibility to retrieve the
* {@link HookContext} of the current hook.
*
* @author Sebastian Sdorra
* @since 1.33
*/
public class ExtendedRepositoryHookEvent extends AbstractRepositoryHookEvent
{
/**
* Constructs a new {@link ExtendedRepositoryHookEvent}.
*
* @param context context of current hook
* @param repository
* @param type type of current hook
*/
public ExtendedRepositoryHookEvent(HookContext context,
Repository repository, RepositoryHookType type)
{
this.context = context;
this.repository = repository;
this.type = type;
}
//~--- get methods ----------------------------------------------------------
/**
* {@inheritDoc}
*
* @deprecated use {@link HookChangesetBuilder#getChangesets()} instead.
*/
@Override
@Deprecated
public Collection<Changeset> getChangesets()
{
return context.getChangesetProvider().getChangesetList();
}
/**
* Returns the context of the current hook.
*
* @return context of current hook
*/
public HookContext getContext()
{
return context;
}
/**
* {@inheritDoc}
*/
@Override
public Repository getRepository()
{
return repository;
}
/**
* {@inheritDoc}
*/
@Override
public RepositoryHookType getType()
{
return type;
}
//~--- set methods ----------------------------------------------------------
/**
* {@inheritDoc}
*
* @deprecated
*/
@Override
@Deprecated
public void setRepository(Repository repository)
{
// do nothing
}
//~--- fields ---------------------------------------------------------------
/** context of current hook */
private HookContext context;
/** modified repository */
private Repository repository;
/** hook type */
private RepositoryHookType type;
}

View File

@@ -1,74 +0,0 @@
/**
* 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;
//~--- JDK imports ------------------------------------------------------------
import java.util.Arrays;
import java.util.Collection;
/**
* Base class for asynchronous post receive repository hook.
*
* @see RepositoryHookType#POST_RECEIVE
* @author Sebastian Sdorra
* @since 1.8
*/
public abstract class PostReceiveRepositoryHook implements RepositoryHook
{
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public Collection<RepositoryHookType> getTypes()
{
return Arrays.asList(RepositoryHookType.POST_RECEIVE);
}
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public boolean isAsync()
{
return true;
}
}

View File

@@ -1,74 +0,0 @@
/**
* 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;
//~--- JDK imports ------------------------------------------------------------
import java.util.Arrays;
import java.util.Collection;
/**
* Base class for pre receive repository hooks.
*
* @see RepositoryHookType#PRE_RECEIVE
* @author Sebastian Sdorra
* @since 1.8
*/
public abstract class PreReceiveRepositoryHook implements RepositoryHook
{
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public Collection<RepositoryHookType> getTypes()
{
return Arrays.asList(RepositoryHookType.PRE_RECEIVE);
}
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public boolean isAsync()
{
return false;
}
}

View File

@@ -1,75 +0,0 @@
/**
* 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;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import sonia.scm.plugin.ExtensionPoint;
/**
*
* @author Sebastian Sdorra
* @since 1.6
*/
@ExtensionPoint
public interface RepositoryHook
{
/**
* Method description
*
*
* @param event
*/
public void onEvent(RepositoryHookEvent event);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Collection<RepositoryHookType> getTypes();
/**
* Method description
*
*
* @return
*/
public boolean isAsync();
}

View File

@@ -33,9 +33,9 @@
package sonia.scm.repository;
//~--- JDK imports ------------------------------------------------------------
//~--- non-JDK imports --------------------------------------------------------
import java.util.Collection;
import sonia.scm.repository.api.HookContext;
/**
* Repository hook event represents an change event of a repository.
@@ -43,42 +43,66 @@ import java.util.Collection;
* @author Sebastian Sdorra
* @since 1.6
*/
public interface RepositoryHookEvent
public class RepositoryHookEvent
{
/**
* Returns a collection of changesets which are added with this repository
* event.
* Constructs a new {@link ExtendedRepositoryHookEvent}.
*
*
* @return a collection of added changesets
* @param context context of current hook
* @param repository
* @param type type of current hook
*/
public Collection<Changeset> getChangesets();
public RepositoryHookEvent(HookContext context, Repository repository,
RepositoryHookType type)
{
this.context = context;
this.repository = repository;
this.type = type;
}
//~--- get methods ----------------------------------------------------------
/**
* Returns the repository which was modified.
* Returns the context of the current hook.
*
*
* @return modified repository
* @return context of current hook
*/
public Repository getRepository();
public HookContext getContext()
{
return context;
}
/**
* Returns the type of hook event.
* Method description
*
*
* @return type of hook event
* @return
*/
public RepositoryHookType getType();
//~--- set methods ----------------------------------------------------------
public Repository getRepository()
{
return repository;
}
/**
* Sets the modified repository. This method is only for internal use and
* should never be called on a hook.
* Method description
*
*
* @param repository modified repository
* @return
*/
void setRepository(Repository repository);
public RepositoryHookType getType()
{
return type;
}
//~--- fields ---------------------------------------------------------------
/** context of current hook */
private final HookContext context;
/** modified repository */
private final Repository repository;
/** hook type */
private final RepositoryHookType type;
}

View File

@@ -1,109 +0,0 @@
/**
* 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;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
/**
*
* @author Sebastian Sdorra
* @since 1.6
*/
public interface RepositoryHookSupport
{
/**
* Registers a new {@link RepositoryHook}.
*
*
* @param hook to register
*/
public void addHook(RepositoryHook hook);
/**
* Register a {@link java.util.Collection} of hooks.
*
* @param hooks to register
*/
public void addHooks(Collection<RepositoryHook> hooks);
/**
* Fires a post receive hook event. This methods calls the
* {@link PostReceiveRepositoryHook#onEvent(RepositoryHookEvent)}
* of each registered {@link PostReceiveRepositoryHook}.
*
* @param repository that has changed
* @param event
*/
public void fireHookEvent(Repository repository, RepositoryHookEvent event);
/**
* Fires a post receive hook event. This methods calls the
* {@link PostReceiveRepositoryHook#onEvent(RepositoryHookEvent)}
* of each registered {@link PostReceiveRepositoryHook}.
*
*
* @param type of the repository
* @param name of the repository
* @param event
*
* @throws RepositoryNotFoundException if the repository could not be found.
*/
public void fireHookEvent(String type, String name, RepositoryHookEvent event)
throws RepositoryNotFoundException;
/**
* Fires a hook event. This methods calls the
* {@link RepositoryHook#onEvent(RepositoryHookEvent)} of each registered
* {@link RepositoryHook}.
*
*
* @param id of the repository
* @param event
*
* @throws RepositoryNotFoundException if the repository could not be found
*/
public void fireHookEvent(String id, RepositoryHookEvent event)
throws RepositoryNotFoundException;
/**
* Unregisters the given {@link RepositoryHook}.
*
*
* @param hook to unregister
*/
public void removeHook(RepositoryHook hook);
}

View File

@@ -1,94 +0,0 @@
/**
* 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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Sebastian Sdorra
*/
public class RepositoryHookTask implements Runnable
{
/** the logger for RepositoryHookTask */
private static final Logger logger =
LoggerFactory.getLogger(RepositoryHookTask.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param hook
* @param event
*/
public RepositoryHookTask(RepositoryHook hook, RepositoryHookEvent event)
{
this.hook = hook;
this.event = event;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
@Override
public void run()
{
if (logger.isDebugEnabled())
{
Object[] args = new Object[] { event.getType(), hook.getClass().getName(),
event.getRepository().getName() };
logger.debug("execute async {} hook {} for repository {}", args);
}
hook.onEvent(event);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private RepositoryHookEvent event;
/** Field description */
private RepositoryHook hook;
}

View File

@@ -55,10 +55,18 @@ import javax.servlet.http.HttpServletRequest;
* @apiviz.uses sonia.scm.repository.RepositoryHandler
*/
public interface RepositoryManager
extends TypeManager<Repository, RepositoryException>,
RepositoryHookSupport
extends TypeManager<Repository, RepositoryException>
{
/**
* Fire {@link RepositoryHookEvent} to the event bus.
*
* @param event hook event
*
* @since 2.0.0
*/
public void fireHookEvent(RepositoryHookEvent event);
/**
* Imports an existing {@link Repository}.
* Note: This method should only be called from a {@link RepositoryHandler}.
@@ -70,7 +78,7 @@ public interface RepositoryManager
* @throws RepositoryException
*/
public void importRepository(Repository repository)
throws IOException, RepositoryException;
throws IOException, RepositoryException;
//~--- get methods ----------------------------------------------------------

View File

@@ -73,82 +73,15 @@ public class RepositoryManagerDecorator
/**
* {@inheritDoc}
*
*
* @param hook
*/
@Override
public void addHook(RepositoryHook hook)
public void fireHookEvent(RepositoryHookEvent event)
{
decorated.addHook(hook);
decorated.fireHookEvent(event);
}
/**
* {@inheritDoc}
*
*
* @param hooks
*/
@Override
public void addHooks(Collection<RepositoryHook> hooks)
{
decorated.addHooks(hooks);
}
/**
* {@inheritDoc}
*
*
* @param repository
* @param event
*/
@Override
public void fireHookEvent(Repository repository, RepositoryHookEvent event)
{
decorated.fireHookEvent(repository, event);
}
/**
* {@inheritDoc}
*
*
* @param type
* @param name
* @param event
*
* @throws RepositoryNotFoundException
*/
@Override
public void fireHookEvent(String type, String name, RepositoryHookEvent event)
throws RepositoryNotFoundException
{
decorated.fireHookEvent(type, name, event);
}
/**
* {@inheritDoc}
*
*
* @param id
* @param event
*
* @throws RepositoryNotFoundException
*/
@Override
public void fireHookEvent(String id, RepositoryHookEvent event)
throws RepositoryNotFoundException
{
decorated.fireHookEvent(id, event);
}
/**
* {@inheritDoc}
*
*
* @param repository
*
* @throws IOException
* @throws RepositoryException
*/
@Override
public void importRepository(Repository repository)
@@ -157,18 +90,6 @@ public class RepositoryManagerDecorator
decorated.importRepository(repository);
}
/**
* {@inheritDoc}
*
*
* @param hook
*/
@Override
public void removeHook(RepositoryHook hook)
{
decorated.removeHook(hook);
}
//~--- get methods ----------------------------------------------------------
/**
@@ -186,7 +107,6 @@ public class RepositoryManagerDecorator
return decorated.get(type, name);
}
/**
* {@inheritDoc}
*
@@ -212,7 +132,6 @@ public class RepositoryManagerDecorator
return decorated;
}
/**
* {@inheritDoc}
*
@@ -270,7 +189,6 @@ public class RepositoryManagerDecorator
return decorated.getHandler(type);
}
/**
* {@inheritDoc}
*

View File

@@ -33,21 +33,13 @@
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.repository.api.HookContext;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
/**
* Base class for {@link RepositoryHookEvent} wrappers.
*
* @author Sebastian Sdorra
* @since 1.23
*/
public class WrappedRepositoryHookEvent
public class WrappedRepositoryHookEvent extends RepositoryHookEvent
{
/**
@@ -58,7 +50,8 @@ public class WrappedRepositoryHookEvent
*/
protected WrappedRepositoryHookEvent(RepositoryHookEvent wrappedEvent)
{
this.wrappedEvent = wrappedEvent;
super(wrappedEvent.getContext(), wrappedEvent.getRepository(),
wrappedEvent.getType());
}
//~--- methods --------------------------------------------------------------
@@ -93,69 +86,4 @@ public class WrappedRepositoryHookEvent
return wrappedEvent;
}
//~--- get methods ----------------------------------------------------------
/**
* Returns a collection of changesets which are added with this repository
* event.
*
*
* @return a collection of added changesets
*/
public Collection<Changeset> getChangesets()
{
return wrappedEvent.getChangesets();
}
/**
* Returns the context of the current hook. The method returns null if no
* context is available for this hook event. It is possible to check if a hook
* is available with the {@link #isContextAvailable()} method.
*
*
* @return context of current hook or null
*
* @since 1.33
*/
public HookContext getContext()
{
HookContext context = null;
if (isContextAvailable())
{
context = ((ExtendedRepositoryHookEvent) wrappedEvent).getContext();
}
return context;
}
/**
* Returns the repository which was modified.
*
*
* @return modified repository
*/
public Repository getRepository()
{
return wrappedEvent.getRepository();
}
/**
* Returns true if a {@link HookContext} is available.
*
*
* @return true if a {@link HookContext} is available
*
* @since 1.33
*/
public boolean isContextAvailable()
{
return wrappedEvent instanceof ExtendedRepositoryHookEvent;
}
//~--- fields ---------------------------------------------------------------
/** wrapped event */
private RepositoryHookEvent wrappedEvent;
}

View File

@@ -35,9 +35,9 @@ package sonia.scm.repository.spi;
import com.google.inject.Inject;
import sonia.scm.repository.ExtendedRepositoryHookEvent;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RepositoryHookEvent;
import sonia.scm.repository.RepositoryHookType;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryNotFoundException;
@@ -165,31 +165,31 @@ public final class HookEventFacade
{
HookContext context =
hookContextFactory.createContext(hookContextProvider, repository);
ExtendedRepositoryHookEvent event =
new ExtendedRepositoryHookEvent(context, repository, type);
RepositoryHookEvent event = new RepositoryHookEvent(context, repository,
type);
repositoryManager.fireHookEvent(repository, event);
repositoryManager.fireHookEvent(event);
hookContextProvider.handleClientDisconnect();
}
//~--- fields -------------------------------------------------------------
/** Field description */
private HookContextFactory hookContextFactory;
private final HookContextFactory hookContextFactory;
/** Field description */
private Repository repository;
private final Repository repository;
/** Field description */
private RepositoryManager repositoryManager;
private final RepositoryManager repositoryManager;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private HookContextFactory hookContextFactory;
private final HookContextFactory hookContextFactory;
/** Field description */
private RepositoryManager repositoryManager;
private final RepositoryManager repositoryManager;
}