1 /* 2 * $Id: Service.java 19191 2010-08-25 21:05:23Z tcarlson $ 3 * -------------------------------------------------------------------------------------- 4 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com 5 * 6 * The software in this package is published under the terms of the CPAL v1.0 7 * license, a copy of which has been included with this distribution in the 8 * LICENSE.txt file. 9 */ 10 11 package org.mule.api.service; 12 13 import org.mule.api.MuleContext; 14 import org.mule.api.MuleEvent; 15 import org.mule.api.MuleException; 16 import org.mule.api.NamedObject; 17 import org.mule.api.component.Component; 18 import org.mule.api.construct.FlowConstruct; 19 import org.mule.api.exception.MessagingExceptionHandler; 20 import org.mule.api.lifecycle.Lifecycle; 21 import org.mule.api.lifecycle.LifecycleManager; 22 import org.mule.api.model.Model; 23 import org.mule.api.processor.MessageProcessor; 24 import org.mule.api.routing.OutboundRouterCollection; 25 import org.mule.api.source.MessageSource; 26 import org.mule.management.stats.ServiceStatistics; 27 import org.mule.service.ServiceAsyncReplyCompositeMessageSource; 28 29 import java.io.Serializable; 30 31 /** 32 * <code>Service</code> is the internal representation of a Mule Managed service. It 33 * is responsible for managing the interaction of events to and from the service as 34 * well as managing pooled resources. 35 */ 36 37 public interface Service extends Serializable, FlowConstruct, Lifecycle, NamedObject 38 { 39 /** 40 * Makes an asynchronous event call to the service. 41 * 42 * @param event the event to consume 43 * @throws MuleException if the event fails to be processed 44 * @deprecated 45 */ 46 void dispatchEvent(MuleEvent event) throws MuleException; 47 48 /** 49 * Makes a synchronous event call to the service. This event will be consumed by 50 * the service and a result returned. 51 * 52 * @param event the event to consume 53 * @return a MuleMessage containing the resulting message and properties 54 * @throws MuleException if the event fails to be processed 55 * @deprecated 56 */ 57 MuleEvent sendEvent(MuleEvent event) throws MuleException; 58 59 /** 60 * Determines whether this service has been started 61 * 62 * @return true is the service is started and ready to receive events 63 */ 64 boolean isStarted(); 65 66 boolean isStopped(); 67 68 /** 69 * Pauses event processing for a single Mule Service. Unlike stop(), a paused 70 * service will still consume messages from the underlying transport, but those 71 * messages will be queued until the service is resumed. 72 */ 73 void pause() throws MuleException; 74 75 /** 76 * Resumes a single Mule Service that has been paused. If the service is not 77 * paused nothing is executed. 78 */ 79 void resume() throws MuleException; 80 81 /** 82 * True if the service is in a paused state, false otherwise 83 * 84 * @return True if the service is in a paused state, false otherwise 85 */ 86 boolean isPaused(); 87 88 MessageSource getMessageSource(); 89 90 /** 91 * Outbound Routers control how events are published by a service once. the 92 * event has been processed. If no router is set. A default will be used that 93 * uses the outboundProvider set on his descriptor to route the event. 94 * 95 * @return the outbound router for this service 96 * @see OutboundRouterCollection 97 */ 98 MessageProcessor getOutboundMessageProcessor(); 99 100 /** 101 * Returns the initial state of this service 102 * 103 * @return the initial state of this service 104 */ 105 String getInitialState(); 106 107 /** 108 * Returns the name of the model that this descriptor is registered with. 109 * @return the name of the model that this descriptor is registered with or null 110 * if this descriptor has not been registered with a model yet 111 */ 112 Model getModel(); 113 114 void setMessageSource(MessageSource messageSource); 115 116 /** 117 * Outbound Routers control how events are published by a service once. the 118 * event has been processed. If no router is set. A default will be used that 119 * uses the outboundProvider set on his descriptor to route the event. 120 * 121 * @param router the outbound router for this service 122 * @see OutboundRouterCollection 123 */ 124 void setOutboundMessageProcessor(MessageProcessor processor); 125 126 /** 127 * Sets the initial state of this service 128 * 129 * @param state the initial state of this service 130 */ 131 void setInitialState(String state); 132 133 void setModel(Model model); 134 135 /** 136 * Returns the Component that is a invoked by a {@link Service} for each incoming 137 * {@link MuleEvent} routed on by the {@link InboundRouterCollection}. 138 */ 139 Component getComponent(); 140 141 /** 142 * Sets the Component that is a invoked by a {@link Service} for each incoming 143 * {@link MuleEvent} routed on by the {@link InboundRouterCollection}. 144 * 145 * @param component 146 */ 147 void setComponent(Component component); 148 149 /** 150 * Returns the Service statistics. This provides Service router and component statistics. 151 */ 152 ServiceStatistics getStatistics(); 153 154 MuleContext getMuleContext(); 155 156 LifecycleManager getLifecycleManager(); 157 158 void setAsyncReplyMessageSource(ServiceAsyncReplyCompositeMessageSource asyncReplyMessageSource); 159 160 ServiceAsyncReplyCompositeMessageSource getAsyncReplyMessageSource(); 161 162 MessagingExceptionHandler getExceptionListener(); 163 164 void setExceptionListener(MessagingExceptionHandler exceptionListener); 165 }