001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.synapse.endpoints;
021:
022: import org.apache.synapse.MessageContext;
023:
024: /**
025: * Endpoint defines the behavior common to all Synapse endpoints. Synapse endpoints should be able
026: * to send the given Synapse message context, rather than just providing the information for sending
027: * the message. The task a particular endpoint does in its send(...) method is specific to the endpoint.
028: * For example a loadbalance endpoint may choose another endpoint using its load balance policy and
029: * call its send(...) method while an address endpoint (leaf level) may send the message to an actual
030: * endpoint url. Endpoints may contain zero or more endpoints in them and build up a hierarchical
031: * structure of endpoints.
032: */
033: public interface Endpoint {
034:
035: /**
036: * Sends the message context according to an endpoint specific behavior.
037: *
038: * @param synMessageContext MessageContext to be sent.
039: */
040: public void send(MessageContext synMessageContext);
041:
042: /**
043: * Endpoints that contain other endpoints should implement this method. It will be called if a
044: * child endpoint causes an exception. Action to be taken on such failure is up to the implementation.
045: * But it is good practice to first try addressing the issue. If it can't be addressed propagate the
046: * exception to parent endpoint by calling parent endpoint's onChildEndpointFail(...) method.
047: *
048: * @param endpoint The child endpoint which caused the exception.
049: * @param synMessageContext MessageContext that was used in the failed attempt.
050: */
051: public void onChildEndpointFail(Endpoint endpoint,
052: MessageContext synMessageContext);
053:
054: /**
055: * Sets the parent endpoint for the current endpoint.
056: *
057: * @param parentEndpoint parent endpoint containing this endpoint. It should handle the onChildEndpointFail(...)
058: * callback.
059: */
060: public void setParentEndpoint(Endpoint parentEndpoint);
061:
062: /**
063: * Returns the name of the endpoint.
064: *
065: * @return Endpoint name.
066: */
067: public String getName();
068:
069: /**
070: * Sets the name of the endpoint. Local registry use this name as the key for storing the
071: * endpoint.
072: *
073: * @param name Name for the endpoint.
074: */
075: public void setName(String name);
076:
077: /**
078: * Returns if the endpoint is currently active or not. Messages should not be sent to inactive
079: * endpoints.
080: *
081: * @param synMessageContext MessageContext for the current message. This is required for
082: * IndirectEndpoints where the actual endpoint is retrieved from the MessageContext. Other
083: * Endpoint implementations may ignore this parameter.
084: * @return true if the endpoint is in active state. false otherwise.
085: */
086: public boolean isActive(MessageContext synMessageContext);
087:
088: /**
089: * Sets the endpoint as active or inactive. If an endpoint is detected as failed, it should be
090: * set as inactive. But endpoints may be eventually set as active by the endpoint refresher to
091: * avoid ignoring endpoints forever.
092: *
093: * @param active true if active. false otherwise.
094: * @param synMessageContext MessageContext for the current message. This is required for
095: * IndirectEndpoints where the actual endpoint is retrieved from the MessageContext. Other
096: * Endpoint implementations may ignore this parameter.
097: */
098: public void setActive(boolean active,
099: MessageContext synMessageContext);
100: }
|