jconsole doesn't understand Ternary

This commit is contained in:
Chiradeep Vittal 2011-08-31 10:03:44 -07:00
parent 3c5becbd95
commit 78ded9c78e
5 changed files with 53 additions and 24 deletions

View File

@ -198,6 +198,22 @@ public class LocalSecurityGroupWorkQueue implements SecurityGroupWorkQueue {
}
}
@Override
public List<Long> getVmsInQueue() {
List<Long> vmIds = new ArrayList<Long>();
_lock.lock();
try {
Iterator<SecurityGroupWork> iter = _currentWork.iterator();
while (iter.hasNext()) {
vmIds.add(iter.next().getInstanceId());
}
} finally {
_lock.unlock();
}
return vmIds;
}
}

View File

@ -236,8 +236,11 @@ public class SecurityGroupManagerImpl2 extends SecurityGroupManagerImpl{
public int getQueueSize() {
return _workQueue.size();
}
public SecurityGroupWorkQueue getWorkQueue() {
return _workQueue;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {

View File

@ -17,9 +17,9 @@
*/
package com.cloud.network.security;
import java.util.List;
import java.util.Map;
import java.util.Date;
import com.cloud.utils.Ternary;
/**
* Allows JMX access
@ -28,8 +28,12 @@ import com.cloud.utils.Ternary;
public interface SecurityGroupManagerMBean {
void enableUpdateMonitor(boolean enable);
Map<Long, Ternary<Date, Date, Long>> getVmUpdateDetails();
Map<Long, Date> getScheduledTimestamps();
Map<Long, Date> getLastUpdateSentTimestamps();
int getQueueSize();
List<Long> getVmsInQueue();
}

View File

@ -37,4 +37,6 @@ public interface SecurityGroupWorkQueue {
int size();
void clear();
List<Long> getVmsInQueue();
}

View File

@ -1,19 +1,19 @@
package com.cloud.network.security;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.management.StandardMBean;
import com.cloud.utils.Ternary;
public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityGroupManagerMBean, RuleUpdateLog {
SecurityGroupManagerImpl2 _sgMgr;
boolean _monitoringEnabled = false;
//keep track of last scheduled, last update sent and last seqno sent per vm. Make it available over JMX
Map<Long, Ternary<Date, Date, Long>> _updateDetails = new ConcurrentHashMap<Long, Ternary<Date,Date,Long>>(4000, 100, 64);
Map<Long, Date> _scheduleTimestamps = new ConcurrentHashMap<Long, Date>(4000, 100, 64);
Map<Long, Date> _updateTimestamps = new ConcurrentHashMap<Long, Date>(4000, 100, 64);
protected SecurityManagerMBeanImpl(SecurityGroupManagerImpl2 securityGroupManager) {
@ -22,10 +22,7 @@ public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityG
}
@Override
public Map<Long, Ternary<Date, Date, Long>> getVmUpdateDetails() {
return _updateDetails;
}
@Override
public int getQueueSize() {
@ -35,13 +32,7 @@ public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityG
@Override
public void logUpdateDetails(Long vmId, Long seqno) {
if (_monitoringEnabled) {
Ternary<Date, Date, Long> detail = _updateDetails.get(vmId);
if (detail == null) {
detail = new Ternary<Date, Date, Long>(new Date(), new Date(), seqno);
}
detail.second(new Date());
detail.third(seqno);
_updateDetails.put(vmId, detail);
_updateTimestamps.put(vmId, new Date());
}
}
@ -50,12 +41,7 @@ public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityG
public void logScheduledDetails(Set<Long> vmIds) {
if (_monitoringEnabled) {
for (Long vmId : vmIds) {
Ternary<Date, Date, Long> detail = _updateDetails.get(vmId);
if (detail == null) {
detail = new Ternary<Date, Date, Long>(new Date(), null, 0L);
}
detail.first(new Date());
_updateDetails.put(vmId, detail);
_scheduleTimestamps.put(vmId, new Date());
}
}
}
@ -64,8 +50,26 @@ public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityG
public void enableUpdateMonitor(boolean enable) {
_monitoringEnabled = enable;
if (!enable) {
_updateDetails.clear();
_updateTimestamps.clear();
_scheduleTimestamps.clear();
}
}
@Override
public Map<Long, Date> getScheduledTimestamps() {
return _scheduleTimestamps;
}
@Override
public Map<Long, Date> getLastUpdateSentTimestamps() {
return _updateTimestamps;
}
@Override
public List<Long> getVmsInQueue() {
return _sgMgr.getWorkQueue().getVmsInQueue();
}
}