+++ /dev/null
-/*
- * Copyright 2011-2012 GRNET S.A. 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.
- *
- * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``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 GRNET S.A 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.
- *
- * The views and conclusions contained in the software and
- * documentation are those of the authors and should not be
- * interpreted as representing official policies, either expressed
- * or implied, of GRNET S.A.
- */
-
-package gr.grnet.aquarium.connector.handler
-
-/**
- * An executor for a [[gr.grnet.aquarium.connector.handler.PayloadHandler]].
- *
- * @author Christos KK Loverdos <loverdos@gmail.com>
- */
-
-trait PayloadHandlerExecutor {
- def exec(payload: Array[Byte], handler: PayloadHandler)
- (onSuccess: HandlerResult ⇒ Any)
- (onError: Throwable ⇒ Any): Unit
-}
+++ /dev/null
-/*
- * Copyright 2011-2012 GRNET S.A. 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.
- *
- * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``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 GRNET S.A 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.
- *
- * The views and conclusions contained in the software and
- * documentation are those of the authors and should not be
- * interpreted as representing official policies, either expressed
- * or implied, of GRNET S.A.
- */
-
-package gr.grnet.aquarium.connector.handler
-
-/**
- * A [[gr.grnet.aquarium.connector.handler.PayloadHandlerExecutor]] that calls the
- * [[gr.grnet.aquarium.connector.handler.PayloadHandler]] synchronously.
- *
- * @author Christos KK Loverdos <loverdos@gmail.com>
- */
-
-final class SynchronousPayloadHandlerExecutor extends PayloadHandlerExecutor {
-
- def exec(payload: Array[Byte], handler: PayloadHandler)
- (onSuccess: HandlerResult ⇒ Any)
- (onError: Throwable ⇒ Any): Unit = {
-
- try onSuccess(handler.handlePayload(payload))
- catch { case e: Throwable ⇒ onError(e) }
- }
-}
handler: PayloadHandler,
/**
- * Specifies how we execute the handler
- */
- executor: PayloadHandlerExecutor,
-
- /**
* After the payload is processed, we call this function with ourselves and the result.
*/
notifier: (RabbitMQConsumer, Maybe[HandlerResult]) ⇒ Unit
val onSuccessF = onSuccessBasicStepF andThen notifierF
- executor.exec(body, handler) (onSuccessF) (onErrorF)
+ try {
+ val result0 = handler.handlePayload(body)
+ val result1 = onSuccessF.apply(result0)
+ result1
+ }
+ catch(onErrorF)
}
- catch (onErrorF)
+ catch(onErrorF)
}
}
import gr.grnet.aquarium.connector.rabbitmq.service.PayloadHandlerPostNotifier
import gr.grnet.aquarium.connector.rabbitmq.conf.RabbitMQKeys.RabbitMQConfKeys
import gr.grnet.aquarium.connector.rabbitmq.conf.RabbitMQKeys
-import gr.grnet.aquarium.connector.handler.{SynchronousPayloadHandlerExecutor, ResourceEventPayloadHandler, IMEventPayloadHandler}
-import gr.grnet.aquarium.util.json.JsonSupport
+import gr.grnet.aquarium.connector.handler.{ResourceEventPayloadHandler, IMEventPayloadHandler}
/**
* The service that is responsible to handle `RabbitMQ` connectivity.
val imHandler = new IMEventPayloadHandler(aquarium, logger)
- val futureExecutor = new SynchronousPayloadHandlerExecutor
-
// (e)xchange:(r)outing key:(q)
// These two are to trigger an error if the property does not exist
aquarium,
rccc,
rcHandler,
- futureExecutor,
postNotifier
)
}
aquarium,
imcc,
imHandler,
- futureExecutor,
postNotifier
)
}