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

uk.org.retep.util.messaging.router.RouterAdapter Maven / Gradle / Ivy

There is a newer version: 10.6
Show newest version
/*
 * 

Copyright (c) 1998-2009, Peter T Mount
* All rights reserved.

* *

Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met:

* *
    *
  • Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer.
  • * *
  • 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.
  • * *
  • Neither the name of the retep.org.uk 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 COPYRIGHT OWNER * 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.

*/ package uk.org.retep.util.messaging.router; import java.util.Collection; import javax.annotation.Nonnull; import javax.annotation.Nullable; import uk.org.retep.util.messaging.Component; import uk.org.retep.util.messaging.Message; import uk.org.retep.util.messaging.MessageException; import uk.org.retep.util.messaging.MessagingService; import uk.org.retep.util.messaging.Router; /** * An adapter which wraps another Router implementation * * @param Type of the address * @param Type used to represent a route * @author peter * @since 9.5 */ public class RouterAdapter implements Router { private final Router router; /** * @param router */ public RouterAdapter( @Nonnull final Router router ) { this.router = router; } @SuppressWarnings( "unchecked" ) @Nonnull protected final > T getRouter() { return (T) router; } /** * {@inheritDoc } */ @Override @Nullable public K getKey() { return router.getKey(); } /** * {@inheritDoc } */ @Override public void add( @Nonnull final Component> component ) throws MessageException { router.add( component ); } /** * {@inheritDoc } */ @Override public boolean addRoute( @Nonnull final R route, @Nonnull final Component component ) throws MessageException { return router.addRoute( route, component ); } /** * {@inheritDoc } */ @Override public boolean removeRoute( @Nonnull final R route ) { return router.removeRoute( route ); } /** * {@inheritDoc } */ @Override public boolean removeComponent( @Nonnull final Component component ) { return router.removeComponent( component ); } /** * {@inheritDoc } */ @Override @Nonnull public Collection getRoutes() { return router.getRoutes(); } /** * {@inheritDoc } */ @Override @Nonnull public Collection> getComponents() { return router.getComponents(); } /** * {@inheritDoc } */ @Override public void consume( @Nonnull final Message message ) throws MessageException { router.consume( message ); } /** * {@inheritDoc } */ @Override public void setMessagingService( @Nonnull final MessagingService messagingService ) throws MessageException { router.setMessagingService( messagingService ); } /** * {@inheritDoc } * *

* Subclasses must call super or call the same method * in the router otherwise the router will fail during use. *

*/ @Override public void startComponent() throws MessageException { router.startComponent(); } /** * {@inheritDoc } * *

* Subclasses must call super or call the same method * in the router otherwise the router will fail during use. *

*/ @Override public void stopComponent() { router.stopComponent(); } /** * {@inheritDoc } * *

* Subclasses must call super or call the same method * in the router otherwise the router will fail during use. *

*/ @Override public boolean isComponentStarted() { return router.isComponentStarted(); } @Override public String toString() { final K key = getKey(); if( key == null ) { return super.toString(); } else { return getClass().getName() + "[" + key + "]"; } } @Override public int hashCode() { final K key = getKey(); if( key == null ) { return super.hashCode(); } else { return key.hashCode(); } } @Override public boolean equals( final Object obj ) { if( obj == null ) { return false; } if( getClass() != obj.getClass() ) { return false; } @SuppressWarnings( "unchecked" ) final RouterAdapter other = (RouterAdapter) obj; final K key = getKey(); final K otherKey = other.getKey(); return !(key != otherKey && (key == null || !key.equals( otherKey ))); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy