public final class AddressFilter extends Object implements Serializable
InetSocketAddresses and determines if
a given address passes the filter. An address passes if:
This filter acts as a positive filter. Only clients whose address is listed may connect. eBus does not use a negative filter where all clients are accepted except those listed.
An address filter may be defined in text for storage purposes.
The format is <address>[',' <address>]*
where <address> format is either
(host | IP address) ':' port or just
(host | IP address) and port is assumed to be
zero.
net.sf.eBus.client.EServer can be configured to use an
address filter, restricting accepted connections to those
specified by the filter.
As of eBus release 7.1.0, an address filter may be loaded from
a com.typesafe HOCON configuration.
| Constructor and Description |
|---|
AddressFilter()
Creates an empty address filter.
|
AddressFilter(Collection<InetSocketAddress> c)
Creates a new address filter containing those elements in
the specified collection.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(InetSocketAddress address)
Adds the address to the filter set.
|
boolean |
addAll(Collection<InetSocketAddress> c)
Adds all the addresses in the collection to this set.
|
void |
clear()
Removes all addresses from this filter.
|
boolean |
contains(InetSocketAddress address)
Returns
true if this address filter contains the
specified address; otherwise returns false. |
boolean |
equals(Object o)
Compares the given object with this filter for equality.
|
int |
hashCode()
Returns the hash code value for this set.
|
boolean |
isEmpty()
Returns
true if this address filter is empty. |
static AddressFilter |
load(com.typesafe.config.Config config,
String key)
Returns an address filter extracted from the given JSON
configuration.
|
static AddressFilter |
parse(String s)
Returns the address filter parsed from the given text.
|
boolean |
passes(InetSocketAddress iAddress)
Returns
true if iAddress is acceptable
to this filter and false otherwise. |
boolean |
remove(InetSocketAddress address)
Removes the specified address from this filter if it is
present.
|
boolean |
removeAll(Collection<InetSocketAddress> c)
Removes all the specified addresses from this filter.
|
int |
size()
Returns the address filter size.
|
String |
toString()
Returns the address filter in text, formatted for storage
in
EConfigure. |
public AddressFilter()
public AddressFilter(Collection<InetSocketAddress> c)
c - collection whose elements will comprise the new
address filter.public boolean equals(Object o)
true if o is a
non-null AddressFilter with the same size and
addresses as this filter; otherwise, returns
false.public int hashCode()
null
element is defined to be zero. This ensures that
s1.equals(s2) implies that
s1.hashCode()==s2.hashCode() for any two sets
s1 and s2, as required by the general
contract of Object.hashCode().public String toString()
EConfigure.public boolean isEmpty()
true if this address filter is empty.true if this address filter is empty.public int size()
public boolean contains(InetSocketAddress address)
true if this address filter contains the
specified address; otherwise returns false.address - look for this object in the filter set.true if address is in the filter.public boolean add(InetSocketAddress address)
address - the address added to this filter.true if this filter did not already
contain address.NullPointerException - if address is null.public boolean addAll(Collection<InetSocketAddress> c)
c - the addresses to be added to this collection.true if the filter changed as a result of
this call.NullPointerException - if either c is null or contains a
null element.public boolean remove(InetSocketAddress address)
true if the filter contained this
address.address - remove this address if present.true if the address was removed.NullPointerException - if address is null.public boolean removeAll(Collection<InetSocketAddress> c)
true if this filter was changed by this
operation.c - addresses to be removed.true if this filter was changed by this
operation.NullPointerException - if c is null or contains a null
address.public void clear()
public boolean passes(InetSocketAddress iAddress)
true if iAddress is acceptable
to this filter and false otherwise.iAddress - Check if this address is in the filter.true if iAddress is acceptable
to this filter and false otherwise.public static AddressFilter parse(String s) throws ParseException
Returns a non-null empty address filter if not
defined.
s - the address filter text.ParseException - if s is either improperly formatted or contains
an invalid filter address.public static AddressFilter load(com.typesafe.config.Config config, String key)
Returns a non-null empty address filter if not
defined.
config - JSON configuration containing address
filter.key - address filter list is stored under this key.com.typesafe.config.ConfigException - if config contains an improperly formatted filter.Copyright © 2019. All rights reserved.