aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/service/netaddr/event/ChangeEvent.java
blob: 262cf03158fe7aa509c524f86bbfd8c20b01e313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.service.netaddr.event;

import java.net.*;

/**
 * A ChangeEvent is fired on change of the network configuration of the computer.
 *
 * @author Damian Minkov
 */
public class ChangeEvent
    extends java.util.EventObject
{
    /**
     * Serial version UID.
     */
    private static final long serialVersionUID = 0L;

    /**
     * Event type for interface going down.
     */
    public static final int IFACE_DOWN = 0;

    /**
     * Event type for interface going up.
     */
    public static final int IFACE_UP = 1;

    /**
     * Event type for address going down.
     */
    public static final int ADDRESS_DOWN = 2;

    /**
     * Event type for interface going down.
     */
    public static final int ADDRESS_UP = 3;

    /**
     * Event type for dns change.
     */
    public static final int DNS_CHANGE = 4;

    /**
     * The type of the current event.
     */
    private int type = -1;

    /**
     * Whether this event is after computer have been suspended.
     */
    private boolean standby = false;

    /**
     * The address that changed.
     */
    private InetAddress address;

    /**
     * Is this event initial one. When starting, no actual
     * change has occurred in the system.
     */
    private boolean initial;

    /**
     * Creates event.
     * @param source the source of the event, the interface.
     * @param type the type of the event.
     * @param address the address that changed.
     * @param standby is the event after a suspend of the computer.
     * @param initial is this event initial one.
     */
    public ChangeEvent(Object source,
                       int type,
                       InetAddress address,
                       boolean standby,
                       boolean initial)
    {
        super(source);

        this.type = type;
        this.address = address;
        this.standby = standby;
        this.initial = initial;
    }

    /**
     * Creates event.
     * @param source the source of the event, the interface.
     * @param type the type of the event.
     * @param address the address that changed.
     */
    public ChangeEvent(Object source,
                       int type,
                       InetAddress address)
    {
        this(source, type, address, false, false);
    }

    /**
     * Creates event.
     * @param source the source of the event, the interface.
     * @param type the type of the event.
     */
    public ChangeEvent(Object source, int type)
    {
        this(source, type, null, false, false);
    }

    /**
     * Creates event.
     * @param source the source of the event.
     * @param type the type of the event.
     * @param standby is the event after a suspend of the computer.
     */
    public ChangeEvent(Object source, int type, boolean standby)
    {
        this(source, type, null, standby, false);
    }

    /**
     * The type of this event.
     * @return the type
     */
    public int getType()
    {
        return type;
    }

    /**
     * The address that changed.
     * @return the address
     */
    public InetAddress getAddress()
    {
        return address;
    }

    /**
     * Whether this event is after suspend of the computer.
     * @return the standby
     */
    public boolean isStandby()
    {
        return standby;
    }

    /**
     * Overrides toString method.
     * @return string representing the event.
     */
    @Override
    public String toString()
    {
        StringBuilder buff = new StringBuilder();
        buff.append("ChangeEvent ");

        switch(type)
        {
            case IFACE_DOWN: buff.append("Interface down"); break;
            case IFACE_UP: buff.append("Interface up"); break;
            case ADDRESS_DOWN : buff.append("Address down"); break;
            case ADDRESS_UP : buff.append("Address up"); break;
            case DNS_CHANGE : buff.append("Dns has changed"); break;
        }

        buff.append(", standby=" + standby)
            .append(", source=" + source)
            .append(", address=" + address)
            .append(", isInitial=" + initial);

        return buff.toString();
    }

    /**
     * Is this event initial one. When starting, no actual
     * change has occurred in the system.
     * @return is this event initial one.
     */
    public boolean isInitial()
    {
        return initial;
    }
}