1 /* 2 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com 3 * The software in this package is published under the terms of the CPAL v1.0 4 * license, a copy of which has been included with this distribution in the 5 * LICENSE.txt file. 6 */ 7 package org.mule.api.transport; 8 9 import org.mule.api.lifecycle.Lifecycle; 10 import org.mule.api.retry.RetryContext; 11 12 /** 13 * Interface for objects that should connect to a resource. 14 */ 15 public interface Connectable extends Lifecycle 16 { 17 18 /** 19 * Make the connection to the underlying transport. The fact that this object is 20 * connected or not should have no influence on the lifecycle, especially the 21 * start / stop state if applicable. 22 * 23 * @throws Exception 24 */ 25 void connect() throws Exception; 26 27 /** 28 * Disconnect the from the underlying transport 29 * 30 * @throws Exception 31 */ 32 void disconnect() throws Exception; 33 34 /** 35 * Determines if this object is connected or not 36 */ 37 boolean isConnected(); 38 39 /** 40 * Returns a string identifying the underlying resource 41 */ 42 String getConnectionDescription(); 43 44 /** 45 * Test whether the connector is able to connect to its resource(s). 46 * This will allow a retry policy to go into effect in the case of failure. Implementations must 47 * call either: 48 * <ul> 49 * <li>{@link RetryContext#setOk()} when no problems found (or no validation required). 50 * <li>{@link RetryContext#setFailed(Throwable)} with a root cause for a connection failure. 51 * </ul> 52 * Callers should then check for {@link RetryContext#isOk()}. The failure, if any, will be 53 * provided via the {@link RetryContext#getLastFailure()}. 54 * 55 * @return same retry context with status info set and any failures populated 56 * @throws Exception if the connector fails to connect @param retryContext 57 */ 58 RetryContext validateConnection(RetryContext retryContext); 59 }