/jboss-as-7.1.1.Final/controller/src/main/java/org/jboss/as/controller/interfaces/LoopbackInterfaceCriteria.java
Java | 42 lines | 19 code | 9 blank | 14 comment | 1 complexity | d2aebe145d6a5ead4ac08abbfa3be795 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
1/**
2 *
3 */
4package org.jboss.as.controller.interfaces;
5
6import java.io.ObjectStreamException;
7import java.net.InetAddress;
8import java.net.NetworkInterface;
9import java.net.SocketException;
10
11/**
12 * {@link InterfaceCriteria} that tests whether a given interface is a
13 * {@link NetworkInterface#isLoopback() loopback interface}
14 *
15 * @author Brian Stansberry
16 */
17public class LoopbackInterfaceCriteria implements InterfaceCriteria {
18
19 private static final long serialVersionUID = 1922501758657303593L;
20
21 public static final LoopbackInterfaceCriteria INSTANCE = new LoopbackInterfaceCriteria();
22
23 private LoopbackInterfaceCriteria() {}
24
25 /**
26 * {@inheritDoc}
27 *
28 * @return <code>address</code> if {@link NetworkInterface#isLoopback()} is true, null otherwise.
29 */
30 @Override
31 public InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {
32
33 if( networkInterface.isLoopback() )
34 return address;
35 return null;
36 }
37
38 private Object readResolve() throws ObjectStreamException {
39 return INSTANCE;
40 }
41
42}