use of alma.acs.nsstatistics.ChannelData in project ACS by ACS-Community.
the class SubscribeNCHandler method canExecute.
@CanExecute
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object obj, MHandledItem handledItem) {
boolean canExecute = false;
if (subscriptionChangeJobMap.isEmpty()) {
// disable while previous subscription change actions are still running
List<ChannelData> ncList = getSelectedNCs(obj);
if (!ncList.isEmpty()) {
canExecute = true;
// if multiple NCs are selected, they must all be in the same subscription state,
// otherwise we don't allow the subscription change
Boolean sharedIsSubscribed = null;
for (ChannelData nc : ncList) {
// all selected NCs must be subscribable
if (!nc.isSubscribable()) {
canExecute = false;
break;
}
if (sharedIsSubscribed == null) {
// the first NC we are checking
sharedIsSubscribed = new Boolean(eventModel.isSubscribed(nc));
} else {
if (eventModel.isSubscribed(nc) != sharedIsSubscribed.booleanValue()) {
canExecute = false;
break;
}
}
}
// We dynamically update the menu item state to display the correct toggle symbol.
if (canExecute) {
handledItem.setSelected(sharedIsSubscribed);
}
}
}
return canExecute;
}
use of alma.acs.nsstatistics.ChannelData in project ACS by ACS-Community.
the class SubscribeNCHandler method execute.
/**
* Allows one or many NCs to be selected, which is why we use 'Object' instead of 'ChannelData' as the selection.
*/
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Object obj, MHandledItem handledItem) {
List<ChannelData> ncList = getSelectedNCs(obj);
for (ChannelData nc : ncList) {
// We simply toggle the subscription, ignoring the CHECK menu item state.
// In fact we have to manually toggle the menu in the end, since the UI-induced toggling got lost
// when eclipse called 'canExecute' right before this method.
boolean previousIsSubscribed = eventModel.isSubscribed(nc);
SubscriptionChangeJob job = (previousIsSubscribed ? new UnsubscribeJob(nc) : new SubscribeJob(nc));
subscriptionChangeJobMap.put(nc.getName(), job);
job.schedule();
handledItem.setSelected(!previousIsSubscribed);
}
}
use of alma.acs.nsstatistics.ChannelData in project ACS by ACS-Community.
the class nsStatisticsService method run.
/**
*
*/
public void run() {
// 1min
long acqFreq = ACQUISITION_FREQUENCY;
// at least 1min
long logFreq = params.getFrequency();
if (logFreq < acqFreq) {
logger.log(AcsLogLevel.WARNING, "Statistics of Notification Services will be obtained with a very high frequency (less than 1 minute time interval)");
acqFreq = logFreq;
}
logger.log(AcsLogLevel.INFO, "Acquisition frequency: " + String.valueOf(acqFreq) + "ms");
logger.log(AcsLogLevel.INFO, "Log frequency: " + String.valueOf(logFreq) + "ms");
acqFreq = acqFreq / MAIN_LOOP_FREQUENCY;
logFreq = logFreq / MAIN_LOOP_FREQUENCY;
boolean nsExists = false;
long counter = 0;
while (stop == false) {
try {
if (// Time to get statistics from the channels
counter % acqFreq == 0) {
nsExists = eventModel.getChannelStatistics();
if (false == nsExists) {
setServicesStatus(Status.UNKNOWN);
if (eventModel.reconnectNamingService() == false) {
logger.log(AcsLogLevel.ERROR, "Naming Service is unreachable");
} else {
nsExists = true;
}
// Calculate statistics
} else {
// Get notify services
NotifyServices ns = eventModel.getNotifyServicesRoot();
// Get services to be treated
List<NotifyServiceData> services = getCurrentServices();
// Get channels to be treated
List<ChannelData> channels = getCurrentChannels(ns);
// Update status of services and channels
updateStatus(services, channels);
}
}
// It's time to log statistics
if (true == nsExists && (counter + 1) % logFreq == 0) {
// Log services and channels statistics
logStatus();
// After logging statistics, we have to reset them
resetStats();
}
} catch (Exception e) {
logger.warning("Notification Service doesn't exist!");
String str = "";
StackTraceElement[] stack = e.getStackTrace();
for (int k = 0; k < stack.length; ++k) {
str += stack[k] + "\n";
}
logger.warning(e.getMessage() + "\n" + str);
}
try {
++counter;
sleep(MAIN_LOOP_FREQUENCY);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
logger.info("nsStatisticsService thread has been finished");
}
use of alma.acs.nsstatistics.ChannelData in project ACS by ACS-Community.
the class nsStatisticsService method getCurrentChannels.
/**
* Get current channels to be treated
* @param services
*/
protected List<ChannelData> getCurrentChannels(NotifyServices ns) {
ChannelData channel = null;
List<ChannelData> channels = ns.getAllChannels();
List<ChannelData> selChannels = new ArrayList<ChannelData>();
for (Iterator<ChannelData> it = channels.iterator(); it.hasNext(); ) {
channel = it.next();
if (shouldLogChannel(channel.getParent().getName(), channel.getName())) {
selChannels.add(channel);
}
}
return selChannels;
}
use of alma.acs.nsstatistics.ChannelData in project ACS by ACS-Community.
the class nsStatisticsService method updateStatus.
protected void updateStatus(List<NotifyServiceData> services, List<ChannelData> channels) {
NotifyServiceData service = null;
ChannelData channel = null;
// Iterate services passed as input parameter to update their status
for (Iterator<NotifyServiceData> it = services.iterator(); it.hasNext(); ) {
service = it.next();
// Status of the current service already exists
if (status.containsKey(service.getName())) {
ServiceInfo serviceInfo = status.get(service.getName());
if (Status.DISABLED == serviceInfo.status) {
logger.warning("Notify Service '" + service.getName() + "' has been restarted");
serviceInfo.status = Status.ENABLED;
} else if (Status.UNKNOWN == serviceInfo.status) {
logger.warning("Notify Service '" + service.getName() + "' is running");
serviceInfo.status = Status.ENABLED;
}
// Status of the current service didn't exist so we create it
} else {
status.put(service.getName(), new ServiceInfo(Status.ENABLED));
logger.warning("Notify Service '" + service.getName() + "' is running");
}
}
// Iterate channels passed as input parameter to update their status
for (Iterator<ChannelData> it = channels.iterator(); it.hasNext(); ) {
channel = it.next();
String channelName = channel.getQualifiedName();
String serviceName = channel.getParent().getName();
ServiceInfo serviceInfo = null;
if (status.containsKey(serviceName)) {
serviceInfo = status.get(serviceName);
// Status of the service of the current channel doesn't exist so we create it
} else {
serviceInfo = new ServiceInfo(Status.ENABLED);
status.put(serviceName, serviceInfo);
logger.warning("Notify Service '" + serviceName + "' is running");
}
ChannelInfo channelInfo = null;
if (serviceInfo.channels.containsKey(channelName)) {
channelInfo = serviceInfo.channels.get(channelName);
if (Status.DISABLED == channelInfo.status) {
channelInfo.status = Status.ENABLED;
} else if (Status.UNKNOWN == channelInfo.status) {
channelInfo.status = Status.ENABLED;
}
} else {
channelInfo = new ChannelInfo(Status.ENABLED);
serviceInfo.channels.put(channelName, channelInfo);
}
// Update channel statistics
channelInfo.stats.setData(channel);
}
// Iterate services and channels already registered to disable the ones
// that are not found
Set<String> registeredServices = status.keySet();
for (Iterator<String> it = registeredServices.iterator(); it.hasNext(); ) {
String serviceName = it.next();
ServiceInfo serviceInfo = status.get(serviceName);
boolean found = false;
for (Iterator<NotifyServiceData> it2 = services.iterator(); it2.hasNext() && false == found; ) {
service = it2.next();
if (service.getName().equals(serviceName)) {
found = true;
}
}
if (false == found && Status.ENABLED == serviceInfo.status) {
logger.warning("Notify Service '" + serviceName + "' has been stopped");
serviceInfo.status = Status.DISABLED;
}
Set<String> registeredChannels = serviceInfo.channels.keySet();
for (Iterator<String> itc = registeredChannels.iterator(); itc.hasNext(); ) {
String channelName = itc.next();
ChannelInfo channelInfo = serviceInfo.channels.get(channelName);
found = false;
for (Iterator<ChannelData> itc2 = channels.iterator(); itc2.hasNext() && false == found; ) {
channel = itc2.next();
if (channel.getQualifiedName().equals(channelName)) {
found = true;
}
}
if (false == found && Status.ENABLED == channelInfo.status) {
channelInfo.status = Status.DISABLED;
}
}
}
}
Aggregations