Skip to content

Commit 654c5e5

Browse files
committed
StatefulDataSource added
1 parent 574fc3a commit 654c5e5

File tree

3 files changed

+74
-50
lines changed

3 files changed

+74
-50
lines changed

visualvm/application/src/org/graalvm/visualvm/application/Application.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727

2828
import java.beans.PropertyChangeEvent;
2929
import java.beans.PropertyChangeListener;
30-
import org.graalvm.visualvm.core.datasource.DataSource;
3130
import org.graalvm.visualvm.core.datasource.Storage;
32-
import org.graalvm.visualvm.core.datasupport.Stateful;
3331
import org.graalvm.visualvm.host.Host;
3432
import java.io.File;
3533
import java.util.Objects;
34+
import org.graalvm.visualvm.core.datasource.StatefulDataSource;
3635
import org.graalvm.visualvm.core.datasupport.DataRemovedListener;
3736
import org.graalvm.visualvm.core.options.GlobalPreferences;
3837
import org.graalvm.visualvm.core.ui.DataSourceWindowListener;
@@ -44,7 +43,7 @@
4443
*
4544
* @author Jiri Sedlacek
4645
*/
47-
public abstract class Application extends DataSource implements Stateful {
46+
public abstract class Application extends StatefulDataSource {
4847

4948
/**
5049
* Instance representing actually running VisualVM application.
@@ -58,8 +57,6 @@ public abstract class Application extends DataSource implements Stateful {
5857

5958
private String id;
6059
private Host host;
61-
private int state = STATE_AVAILABLE;
62-
private int modCount;
6360

6461

6562
/**
@@ -112,28 +109,6 @@ public final boolean isLocalApplication() {
112109
return Host.LOCALHOST.equals(getHost());
113110
}
114111

115-
116-
public final synchronized int getState() {
117-
return state;
118-
}
119-
120-
public final int getModCount() {
121-
return modCount;
122-
}
123-
124-
protected final synchronized void setState(final int newState) {
125-
final int oldState = state;
126-
state = newState;
127-
if (oldState != newState && newState == STATE_AVAILABLE) {
128-
modCount++;
129-
}
130-
if (DataSource.EVENT_QUEUE.isRequestProcessorThread())
131-
getChangeSupport().firePropertyChange(PROPERTY_STATE, oldState, newState);
132-
else DataSource.EVENT_QUEUE.post(new Runnable() {
133-
public void run() { getChangeSupport().firePropertyChange(PROPERTY_STATE, oldState, newState); };
134-
});
135-
}
136-
137112
protected boolean supportsFinishedRemove() {
138113
return true;
139114
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package org.graalvm.visualvm.core.datasource;
26+
27+
import org.graalvm.visualvm.core.datasupport.Stateful;
28+
29+
/**
30+
*
31+
* @author Tomas Hurka
32+
* @author Jiri Sedlacek
33+
*/
34+
public abstract class StatefulDataSource extends DataSource implements Stateful {
35+
36+
private int state = STATE_AVAILABLE;
37+
private int modCount;
38+
private final Object stateLock = new Object();
39+
40+
public final int getState() {
41+
synchronized (stateLock) {
42+
return state;
43+
}
44+
}
45+
46+
public final int getModCount() {
47+
synchronized (stateLock) {
48+
return modCount;
49+
}
50+
}
51+
52+
protected final void setState(final int newState) {
53+
synchronized (stateLock) {
54+
final int oldState = state;
55+
state = newState;
56+
if (oldState != newState && newState == STATE_AVAILABLE) {
57+
modCount++;
58+
}
59+
if (DataSource.EVENT_QUEUE.isRequestProcessorThread()) {
60+
getChangeSupport().firePropertyChange(PROPERTY_STATE, oldState, newState);
61+
} else {
62+
DataSource.EVENT_QUEUE.post(new Runnable() {
63+
public void run() {
64+
getChangeSupport().firePropertyChange(PROPERTY_STATE, oldState, newState);
65+
}
66+
});
67+
}
68+
}
69+
}
70+
}

visualvm/host/src/org/graalvm/visualvm/host/Host.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@
2727

2828
import java.net.InetAddress;
2929
import java.net.UnknownHostException;
30-
import org.graalvm.visualvm.core.datasource.DataSource;
31-
import org.graalvm.visualvm.core.datasupport.Stateful;
30+
import org.graalvm.visualvm.core.datasource.StatefulDataSource;
3231

3332
/**
3433
* Abstract implementation of Host.
3534
* Each host is defined by a hostname/ip if resolvable or hostname/ip and InetAddress.
3635
*
3736
* @author Jiri Sedlacek
3837
*/
39-
public abstract class Host extends DataSource implements Stateful {
38+
public abstract class Host extends StatefulDataSource {
4039

4140
/**
4241
* Instance representing the localhost.
@@ -50,8 +49,6 @@ public abstract class Host extends DataSource implements Stateful {
5049

5150
private final String hostName;
5251
private InetAddress inetAddress;
53-
private int state = STATE_AVAILABLE;
54-
private int modCount;
5552

5653

5754
/**
@@ -97,24 +94,6 @@ public final InetAddress getInetAddress() {
9794
return inetAddress;
9895
}
9996

100-
public synchronized int getState() {
101-
return state;
102-
}
103-
104-
public int getModCount() {
105-
return modCount;
106-
}
107-
108-
protected final synchronized void setState(int newState) {
109-
int oldState = state;
110-
state = newState;
111-
if (oldState != newState && newState == STATE_AVAILABLE) {
112-
modCount++;
113-
}
114-
getChangeSupport().firePropertyChange(PROPERTY_STATE, oldState, newState);
115-
}
116-
117-
11897
public int hashCode() {
11998
if (Host.UNKNOWN_HOST == this) return super.hashCode();
12099
InetAddress address = getInetAddress();

0 commit comments

Comments
 (0)