8049794: Fix raw and unchecked warnings in jvmstat

Reviewed-by: mchung
This commit is contained in:
Joe Darcy 2014-07-09 17:02:03 -07:00
parent f38db6ce11
commit 037699d88a
11 changed files with 105 additions and 97 deletions

View File

@ -27,6 +27,7 @@ package sun.jvmstat.monitor.event;
import java.util.List;
import sun.jvmstat.monitor.MonitoredVm;
import sun.jvmstat.monitor.Monitor;
/**
* Provides a description of a change in status of the instrumentation
@ -42,13 +43,13 @@ public class MonitorStatusChangeEvent extends VmEvent {
* List of instrumentation objects inserted since the last event.
* Elements of this list will always be of type Monitor.
*/
protected List inserted;
protected List<Monitor> inserted;
/**
* List of instrumentation objects removed since the last event.
* Elements of this list will always be of type Monitor.
*/
protected List removed;
protected List<Monitor> removed;
/**
* Construct a new MonitorStatusChangeEvent.
@ -59,8 +60,8 @@ public class MonitorStatusChangeEvent extends VmEvent {
* @param removed the list of instrumentation objects removed since
* the last event.
*/
public MonitorStatusChangeEvent(MonitoredVm vm, List inserted,
List removed) {
public MonitorStatusChangeEvent(MonitoredVm vm, List<Monitor> inserted,
List<Monitor> removed) {
super(vm);
this.inserted = inserted;
this.removed = removed;
@ -75,7 +76,7 @@ public class MonitorStatusChangeEvent extends VmEvent {
* new instrumentation was inserted, an emply List is
* returned.
*/
public List getInserted() {
public List<Monitor> getInserted() {
return inserted;
}
@ -87,7 +88,7 @@ public class MonitorStatusChangeEvent extends VmEvent {
* instrumentation exported by the MonitoredHost. If no
* instrumentation was removed, an emply List is returned.
*/
public List getRemoved() {
public List<Monitor> getRemoved() {
return removed;
}
}

View File

@ -44,7 +44,7 @@ public class VmStatusChangeEvent extends HostEvent {
* active Java Virtual Machine on the MonitoredHost. This Set will only
* contain Integer objects.
*/
protected Set active;
protected Set<Integer> active;
/**
* The set of Java Virtual Machines started on MonitoredHost since the
@ -52,7 +52,7 @@ public class VmStatusChangeEvent extends HostEvent {
* <em>lvmid</em> for each Java Virtual Machine started on the
* MonitoredHost. This Set will only contain Integer objects.
*/
protected Set started;
protected Set<Integer> started;
/**
* The set of Java Virtual Machines terminated on MonitoredHost since the
@ -60,7 +60,7 @@ public class VmStatusChangeEvent extends HostEvent {
* <em>lvmid</em> for each Java Virtual Machine started on the
* MonitoredHost. This Set will only contain Integer objects.
*/
protected Set terminated;
protected Set<Integer> terminated;
/**
* Construct a new VmStatusChangeEvent instance.
@ -72,8 +72,8 @@ public class VmStatusChangeEvent extends HostEvent {
* @param terminated the set of Java Virtual Machines terminated since
* the last event.
*/
public VmStatusChangeEvent(MonitoredHost host, Set active,
Set started, Set terminated) {
public VmStatusChangeEvent(MonitoredHost host, Set<Integer> active,
Set<Integer> started, Set<Integer> terminated) {
super(host);
this.active = active;
this.started = started;
@ -90,7 +90,7 @@ public class VmStatusChangeEvent extends HostEvent {
* there are no active Java Virtual Machines on the host,
* an empty Set is returned.
*/
public Set getActive() {
public Set<Integer> getActive() {
return active;
}
@ -105,7 +105,7 @@ public class VmStatusChangeEvent extends HostEvent {
* no Java Virtual Machines were recently started on the
* host, an empty Set is returned.
*/
public Set getStarted() {
public Set<Integer> getStarted() {
return started;
}
@ -120,7 +120,7 @@ public class VmStatusChangeEvent extends HostEvent {
* no Java Virtual Machines were recently terminated on the
* host, an empty Set is returned.
*/
public Set getTerminated() {
public Set<Integer> getTerminated() {
return terminated;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -169,7 +169,7 @@ public abstract class AbstractPerfDataBuffer {
try {
Class<?> implClass = Class.forName(classname);
Constructor cons = implClass.getConstructor(new Class[] {
Constructor<?> cons = implClass.getConstructor(new Class<?>[] {
Class.forName("java.nio.ByteBuffer"),
Integer.TYPE
});

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
package sun.jvmstat.perfdata.monitor;
import java.util.List;
import sun.jvmstat.monitor.Monitor;
/**
* Immutable class containing the list of inserted and deleted
@ -39,12 +40,12 @@ public class MonitorStatus {
/**
* The list of Monitors inserted since the last query.
*/
protected List inserted;
protected List<Monitor> inserted;
/**
* The list of Monitors removed since the last query.
*/
protected List removed;
protected List<Monitor> removed;
/**
* Create a MonitorStatus instance.
@ -52,7 +53,7 @@ public class MonitorStatus {
* @param inserted the list of Monitors inserted
* @param removed the list of Monitors removed
*/
public MonitorStatus(List inserted, List removed) {
public MonitorStatus(List<Monitor> inserted, List<Monitor> removed) {
this.inserted = inserted;
this.removed = removed;
}
@ -62,7 +63,7 @@ public class MonitorStatus {
*
* @return List - the List of Monitor objects inserted or an empty List.
*/
public List getInserted() {
public List<Monitor> getInserted() {
return inserted;
}
@ -71,7 +72,7 @@ public class MonitorStatus {
*
* @return List - the List of Monitor objects removed or an empty List.
*/
public List getRemoved() {
public List<Monitor> getRemoved() {
return removed;
}
}

View File

@ -66,7 +66,7 @@ public abstract class PerfDataBufferImpl {
/**
* A cache of resolved monitor aliases.
*/
protected Map aliasCache;
protected Map<String, Monitor> aliasCache;
/**
@ -79,9 +79,9 @@ public abstract class PerfDataBufferImpl {
protected PerfDataBufferImpl(ByteBuffer buffer, int lvmid) {
this.buffer = buffer;
this.lvmid = lvmid;
this.monitors = new TreeMap<String, Monitor>();
this.aliasMap = new HashMap<String, ArrayList<String>>();
this.aliasCache = new HashMap();
this.monitors = new TreeMap<>();
this.aliasMap = new HashMap<>();
this.aliasCache = new HashMap<>();
}
/**
@ -200,12 +200,12 @@ public abstract class PerfDataBufferImpl {
protected Monitor findByAlias(String name) {
assert Thread.holdsLock(this);
Monitor m = (Monitor)aliasCache.get(name);
Monitor m = aliasCache.get(name);
if (m == null) {
ArrayList al = aliasMap.get(name);
ArrayList<String> al = aliasMap.get(name);
if (al != null) {
for (Iterator i = al.iterator(); i.hasNext() && m == null; ) {
String alias = (String)i.next();
for (Iterator<String> i = al.iterator(); i.hasNext() && m == null; ) {
String alias = i.next();
m = monitors.get(alias);
}
}
@ -287,21 +287,21 @@ public abstract class PerfDataBufferImpl {
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher("");
List<Monitor> matches = new ArrayList<Monitor>();
List<Monitor> matches = new ArrayList<>();
Set monitorSet = monitors.entrySet();
Set<Map.Entry<String,Monitor>> monitorSet = monitors.entrySet();
for (Iterator i = monitorSet.iterator(); i.hasNext(); /* empty */) {
Map.Entry me = (Map.Entry)i.next();
String name = (String)me.getKey();
Monitor m = (Monitor)me.getValue();
for (Iterator<Map.Entry<String, Monitor>> i = monitorSet.iterator(); i.hasNext(); /* empty */) {
Map.Entry<String, Monitor> me = i.next();
String name = me.getKey();
Monitor m = me.getValue();
// apply pattern to monitor item name
matcher.reset(name);
// if the pattern matches, then add monitor to list
if (matcher.lookingAt()) {
matches.add((Monitor)me.getValue());
matches.add(me.getValue());
}
}
return matches;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -143,16 +143,17 @@ public class LocalMonitoredVm extends AbstractMonitoredVm {
* @param inserted List of Monitor objects inserted.
* @param removed List of Monitor objects removed.
*/
void fireMonitorStatusChangedEvents(List inserted, List removed) {
@SuppressWarnings("unchecked") // Cast of result of clone
void fireMonitorStatusChangedEvents(List<Monitor> inserted, List<Monitor> removed) {
MonitorStatusChangeEvent ev = null;
ArrayList registered = null;
ArrayList<VmListener> registered = null;
synchronized (listeners) {
registered = (ArrayList)listeners.clone();
}
for (Iterator i = registered.iterator(); i.hasNext(); /* empty */) {
VmListener l = (VmListener)i.next();
for (Iterator<VmListener> i = registered.iterator(); i.hasNext(); /* empty */) {
VmListener l = i.next();
// lazily create the event object;
if (ev == null) {
ev = new MonitorStatusChangeEvent(this, inserted, removed);
@ -190,8 +191,8 @@ public class LocalMonitoredVm extends AbstractMonitoredVm {
super.run();
try {
MonitorStatus status = getMonitorStatus();
List inserted = status.getInserted();
List removed = status.getRemoved();
List<Monitor> inserted = status.getInserted();
List<Monitor> removed = status.getRemoved();
if (!inserted.isEmpty() || !removed.isEmpty()) {
fireMonitorStatusChangedEvents(inserted, removed);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -160,17 +160,18 @@ public class MonitoredHostProvider extends MonitoredHost {
* @param terminated a set of Integer objects containing the vmid of
* terminated Vms since last interval.
*/
private void fireVmStatusChangedEvents(Set active, Set started,
Set terminated) {
ArrayList registered = null;
@SuppressWarnings("unchecked") // Cast of result of clone
private void fireVmStatusChangedEvents(Set<Integer> active, Set<Integer> started,
Set<Integer> terminated) {
ArrayList<HostListener> registered = null;
VmStatusChangeEvent ev = null;
synchronized(listeners) {
registered = (ArrayList)listeners.clone();
}
for (Iterator i = registered.iterator(); i.hasNext(); /* empty */) {
HostListener l = (HostListener)i.next();
for (Iterator<HostListener> i = registered.iterator(); i.hasNext(); /* empty */) {
HostListener l = i.next();
if (ev == null) {
ev = new VmStatusChangeEvent(this, active, started, terminated);
}
@ -186,7 +187,7 @@ public class MonitoredHostProvider extends MonitoredHost {
super.run();
// save the last set of active JVMs
Set lastActiveVms = activeVms;
Set<Integer> lastActiveVms = activeVms;
// get the current set of active JVMs
activeVms = (HashSet<Integer>)vmManager.activeVms();
@ -194,20 +195,20 @@ public class MonitoredHostProvider extends MonitoredHost {
if (activeVms.isEmpty()) {
return;
}
Set<Integer> startedVms = new HashSet<Integer>();
Set<Object> terminatedVms = new HashSet<Object>();
Set<Integer> startedVms = new HashSet<>();
Set<Integer> terminatedVms = new HashSet<>();
for (Iterator i = activeVms.iterator(); i.hasNext(); /* empty */) {
Integer vmid = (Integer)i.next();
for (Iterator<Integer> i = activeVms.iterator(); i.hasNext(); /* empty */) {
Integer vmid = i.next();
if (!lastActiveVms.contains(vmid)) {
// a new file has been detected, add to set
startedVms.add(vmid);
}
}
for (Iterator i = lastActiveVms.iterator(); i.hasNext();
for (Iterator<Integer> i = lastActiveVms.iterator(); i.hasNext();
/* empty */) {
Object o = i.next();
Integer o = i.next();
if (!activeVms.contains(o)) {
// JVM has terminated, remove it from the active list
terminatedVms.add(o);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -246,17 +246,18 @@ public class MonitoredHostProvider extends MonitoredHost {
* Vm Identifiers of terminated JVMs since last
* interval.
*/
private void fireVmStatusChangedEvents(Set active, Set started,
Set terminated) {
ArrayList registered = null;
@SuppressWarnings("unchecked") // Cast of result of clone
private void fireVmStatusChangedEvents(Set<Integer> active, Set<Integer> started,
Set<Integer> terminated) {
ArrayList<HostListener> registered = null;
VmStatusChangeEvent ev = null;
synchronized(listeners) {
registered = (ArrayList)listeners.clone();
}
for (Iterator i = registered.iterator(); i.hasNext(); /* empty */) {
HostListener l = (HostListener)i.next();
for (Iterator<HostListener> i = registered.iterator(); i.hasNext(); /* empty */) {
HostListener l = i.next();
if (ev == null) {
ev = new VmStatusChangeEvent(this, active, started, terminated);
}
@ -267,16 +268,17 @@ public class MonitoredHostProvider extends MonitoredHost {
/**
* Fire hostDisconnectEvent events.
*/
@SuppressWarnings("unchecked") // Cast of result of clone
void fireDisconnectedEvents() {
ArrayList registered = null;
ArrayList<HostListener> registered = null;
HostEvent ev = null;
synchronized(listeners) {
registered = (ArrayList)listeners.clone();
}
for (Iterator i = registered.iterator(); i.hasNext(); /* empty */) {
HostListener l = (HostListener)i.next();
for (Iterator<HostListener> i = registered.iterator(); i.hasNext(); /* empty */) {
HostListener l = i.next();
if (ev == null) {
ev = new HostEvent(this);
}
@ -292,7 +294,7 @@ public class MonitoredHostProvider extends MonitoredHost {
super.run();
// save the last set of active JVMs
Set lastActiveVms = activeVms;
Set<Integer> lastActiveVms = activeVms;
try {
// get the current set of active JVMs
@ -313,20 +315,20 @@ public class MonitoredHostProvider extends MonitoredHost {
return;
}
Set<Integer> startedVms = new HashSet<Integer>();
Set<Object> terminatedVms = new HashSet<Object>();
Set<Integer> startedVms = new HashSet<>();
Set<Integer> terminatedVms = new HashSet<>();
for (Iterator i = activeVms.iterator(); i.hasNext(); /* empty */ ) {
Integer vmid = (Integer)i.next();
for (Iterator<Integer> i = activeVms.iterator(); i.hasNext(); /* empty */ ) {
Integer vmid = i.next();
if (!lastActiveVms.contains(vmid)) {
// a new file has been detected, add to set
startedVms.add(vmid);
}
}
for (Iterator i = lastActiveVms.iterator(); i.hasNext();
for (Iterator<Integer> i = lastActiveVms.iterator(); i.hasNext();
/* empty */ ) {
Object o = i.next();
Integer o = i.next();
if (!activeVms.contains(o)) {
// JVM has terminated, remove it from the active list
terminatedVms.add(o);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -198,16 +198,17 @@ public class RemoteMonitoredVm extends AbstractMonitoredVm {
* @param inserted List of Monitor objects inserted.
* @param removed List of Monitor objects removed.
*/
void fireMonitorStatusChangedEvents(List inserted, List removed) {
ArrayList registered = null;
@SuppressWarnings("unchecked") // Cast of result of clone
void fireMonitorStatusChangedEvents(List<Monitor> inserted, List<Monitor> removed) {
ArrayList<VmListener> registered = null;
MonitorStatusChangeEvent ev = null;
synchronized(listeners) {
registered = (ArrayList)listeners.clone();
}
for (Iterator i = registered.iterator(); i.hasNext(); /* empty */) {
VmListener l = (VmListener)i.next();
for (Iterator<VmListener> i = registered.iterator(); i.hasNext(); /* empty */) {
VmListener l = i.next();
if (ev == null) {
ev = new MonitorStatusChangeEvent(this, inserted, removed);
}
@ -218,16 +219,17 @@ public class RemoteMonitoredVm extends AbstractMonitoredVm {
/**
* Fire MonitoredVmStructureChanged events.
*/
@SuppressWarnings("unchecked") // Cast of result of clone
void fireMonitorsUpdatedEvents() {
ArrayList registered = null;
ArrayList<VmListener> registered = null;
VmEvent ev = null;
synchronized(listeners) {
registered = (ArrayList)listeners.clone();
}
for (Iterator i = registered.iterator(); i.hasNext(); /* empty */) {
VmListener l = (VmListener)i.next();
for (Iterator<VmListener> i = registered.iterator(); i.hasNext(); /* empty */) {
VmListener l = i.next();
if (ev == null) {
ev = new VmEvent(this);
}
@ -256,8 +258,8 @@ public class RemoteMonitoredVm extends AbstractMonitoredVm {
try {
MonitorStatus status = getMonitorStatus();
List inserted = status.getInserted();
List removed = status.getRemoved();
List<Monitor> inserted = status.getInserted();
List<Monitor> removed = status.getRemoved();
if (!inserted.isEmpty() || !removed.isEmpty()) {
fireMonitorStatusChangedEvents(inserted, removed);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -47,7 +47,7 @@ public class PerfDataBuffer extends PerfDataBufferImpl {
private static final boolean DEBUG = false;
private static final int syncWaitMs =
Integer.getInteger("sun.jvmstat.perdata.syncWaitMs", 5000);
private static final ArrayList EMPTY_LIST = new ArrayList(0);
private static final ArrayList<Monitor> EMPTY_LIST = new ArrayList<Monitor>(0);
/*
* the following constants must be kept in sync with struct
@ -190,8 +190,8 @@ public class PerfDataBuffer extends PerfDataBufferImpl {
getNewMonitors(map);
// current implementation doesn't support deletion or reuse of entries
ArrayList removed = EMPTY_LIST;
ArrayList inserted = insertedMonitors;
ArrayList<Monitor> removed = EMPTY_LIST;
ArrayList<Monitor> inserted = insertedMonitors;
insertedMonitors = new ArrayList<Monitor>();
return new MonitorStatus(inserted, removed);
@ -618,14 +618,14 @@ public class PerfDataBuffer extends PerfDataBufferImpl {
/**
* Method to dump debugging information
*/
private void dumpAll(Map map, int lvmid) {
private void dumpAll(Map<String, Monitor> map, int lvmid) {
if (DEBUG) {
Set keys = map.keySet();
Set<String> keys = map.keySet();
System.err.println("Dump for " + lvmid);
int j = 0;
for (Iterator i = keys.iterator(); i.hasNext(); j++) {
Monitor monitor = (Monitor)map.get(i.next());
for (Iterator<String> i = keys.iterator(); i.hasNext(); j++) {
Monitor monitor = map.get(i.next());
System.err.println(j + "\t" + monitor.getName()
+ "=" + monitor.getValue());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -65,7 +65,7 @@ public class PerfDataBuffer extends PerfDataBufferImpl {
private static final boolean DEBUG = false;
private static final int syncWaitMs =
Integer.getInteger("sun.jvmstat.perdata.syncWaitMs", 5000);
private static final ArrayList EMPTY_LIST = new ArrayList(0);
private static final ArrayList<Monitor> EMPTY_LIST = new ArrayList<>(0);
/*
* These are primarily for documentary purposes and the match up
@ -198,10 +198,10 @@ public class PerfDataBuffer extends PerfDataBufferImpl {
getNewMonitors(map);
// current implementation doesn't support deletion of reuse of entries
ArrayList removed = EMPTY_LIST;
ArrayList inserted = insertedMonitors;
ArrayList<Monitor> removed = EMPTY_LIST;
ArrayList<Monitor> inserted = insertedMonitors;
insertedMonitors = new ArrayList<Monitor>();
insertedMonitors = new ArrayList<>();
return new MonitorStatus(inserted, removed);
}
@ -524,7 +524,7 @@ public class PerfDataBuffer extends PerfDataBufferImpl {
System.err.println("Dump for " + lvmid);
int j = 0;
for (Iterator i = keys.iterator(); i.hasNext(); j++) {
for (Iterator<String> i = keys.iterator(); i.hasNext(); j++) {
Monitor monitor = map.get(i.next());
System.err.println(j + "\t" + monitor.getName()
+ "=" + monitor.getValue());