org.apache.flume.api
Class FailoverRpcClient

java.lang.Object
  extended by org.apache.flume.api.AbstractRpcClient
      extended by org.apache.flume.api.FailoverRpcClient
All Implemented Interfaces:
RpcClient

public class FailoverRpcClient
extends AbstractRpcClient
implements RpcClient

Avro/Netty implementation of RpcClient which supports failover. This takes a list of hostname port combinations and connects to the next available (looping back to the first) host, from a given list of agents in the order provided. The properties used to build a FailoverRpcClient must have:

hosts = alias_for_host1 alias_for_host2

...

hosts.alias_for_host1 = hostname1:port1.

hosts.alias_for_host2 = hostname2:port2.

etc

Optionally it can also have a

batch-size = batchSize max-attempts = maxAttempts Given a failure, this client will attempt to append to maxAttempts clients in the hosts list immediately following the failed host (looping back to the beginning of the hosts list.


Field Summary
 
Fields inherited from class org.apache.flume.api.AbstractRpcClient
batchSize, connectTimeout, requestTimeout
 
Constructor Summary
protected FailoverRpcClient()
           
 
Method Summary
 void append(Event event)
          Tries to append an event to the currently connected client.
 void appendBatch(List<Event> events)
          Tries to append a list of events to the currently connected client.
 void close()
          Close the connection.
 void configure(Properties properties)
          Configure the client using the given properties object.
protected  InetSocketAddress getLastConnectedServerAddress()
          Get the last socket address this client connected to.
protected  Integer getMaxTries()
          Get the maximum number of "failed" hosts the client will try to establish connection to before throwing an exception.
 boolean isActive()
          Returns true if this object appears to be in a usable state, and it returns false if this object is permanently disabled.
 
Methods inherited from class org.apache.flume.api.AbstractRpcClient
getBatchSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.flume.api.RpcClient
getBatchSize
 

Constructor Detail

FailoverRpcClient

protected FailoverRpcClient()
Method Detail

getMaxTries

protected Integer getMaxTries()
Get the maximum number of "failed" hosts the client will try to establish connection to before throwing an exception. Failed = was able to set up a connection, but failed / returned error when the client tried to send data,

Returns:
The maximum number of failed retries

append

public void append(Event event)
            throws EventDeliveryException
Tries to append an event to the currently connected client. If it cannot send the event, it tries to send to next available host

Specified by:
append in interface RpcClient
Specified by:
append in class AbstractRpcClient
Parameters:
event - The event to be appended.
Throws:
EventDeliveryException

appendBatch

public void appendBatch(List<Event> events)
                 throws EventDeliveryException
Tries to append a list of events to the currently connected client. If it cannot send the event, it tries to send to next available host

Specified by:
appendBatch in interface RpcClient
Specified by:
appendBatch in class AbstractRpcClient
Parameters:
events - The events to be appended.
Throws:
EventDeliveryException

isActive

public boolean isActive()
Description copied from interface: RpcClient

Returns true if this object appears to be in a usable state, and it returns false if this object is permanently disabled.

If this method returns false, an application must call RpcClient.close() on this object to clean up system resources.

Specified by:
isActive in interface RpcClient
Specified by:
isActive in class AbstractRpcClient

close

public void close()
           throws FlumeException
Close the connection. This function is safe to call over and over.

Specified by:
close in interface RpcClient
Specified by:
close in class AbstractRpcClient
Throws:
FlumeException

getLastConnectedServerAddress

protected InetSocketAddress getLastConnectedServerAddress()
Get the last socket address this client connected to. No guarantee this will be the next it will connect to. If this host is down, it will connect to another host. To be used only from the unit tests!

Returns:
The last socket address this client connected to

configure

public void configure(Properties properties)
               throws FlumeException
Description copied from class: AbstractRpcClient
Configure the client using the given properties object.

Specified by:
configure in class AbstractRpcClient
Throws:
FlumeException - if the client can not be configured using this method, or if the client was already configured once.


Copyright © 2009-2012 Apache Software Foundation. All Rights Reserved.