com.addc.server.commons.monitored.MonitoredImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of addc-svr-monitor Show documentation
Show all versions of addc-svr-monitor Show documentation
Supplies the classes required for monitoring a server with the Amentet Monitoring Service
package com.addc.server.commons.monitored;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.omg.CORBA.SystemException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import com.addc.server.AppContextHelper;
import com.addc.server.commons.ManagedObject;
import com.addc.server.monitoring.MonitoredException;
import com.addc.server.monitoring.MonitoredPOA;
/**
* The MonitoredImpl supplies an implementation of the Monitored IDL interface.
*/
public class MonitoredImpl extends MonitoredPOA {
private static final Logger LOGGER= LoggerFactory.getLogger(MonitoredImpl.class);
private MonitoringClient monitorThread;
/**
* Create a new MonitoredImpl
*/
public MonitoredImpl() {
}
@Override
public void ping() throws MonitoredException {
List errors= new ArrayList<>();
List components= getMonitoringClient().getMonitoredComponents();
List lost= new LinkedList<>();
for (ManagedObject mo : components) {
try {
if (mo.getObjectRef()._non_existent()) {
errors.add(mo.getCorbaloc() + " has been destroyed");
lost.add(mo);
}
} catch (SystemException e) {
LOGGER.error("Unexpected CORBA Exception", e);
}
}
if (!errors.isEmpty()) {
LOGGER.warn("One or more managed Objects have been destroyed: {}", errors);
for (ManagedObject mo : lost) {
monitorThread.removeComponent(mo);
}
throw new MonitoredException(errors.toArray(new String[0]));
}
}
@Override
public String[] monitoredComponents() {
return getMonitoringClient().getMonitoredComponentCorbalocs();
}
/**
* Get a reference to the injected MonitoringClient
*
* @return a reference to the injected MonitoringClient
*/
MonitoringClient getMonitoringClient() {
if (monitorThread == null) {
ApplicationContext context= AppContextHelper.getInstance().getAppContext();
MonitoringClientFactory bean= context.getBean("orbWrapper", MonitoringClientFactory.class);
monitorThread= bean.getMonitoringClient();
}
return monitorThread;
}
}