use of si.ijs.maci.ClientInfo in project ACS by ACS-Community.
the class MaciSupervisorTest method setUp.
@Override
public void setUp() throws Exception {
System.out.println("\n--- " + getName() + " ----------------");
// make the manager
// -----------------------------------------------------------------
orb = Mockito.mock(ORB.class);
manager = Mockito.mock(Manager.class);
administrator = Mockito.mock(Administrator.class);
final int hhhhh = 0;
final int[] empty = new int[] {};
ComponentInfo comp100 = new ComponentInfo("type", "code", null, "comp100", empty, 10, "cont10", 100, 0, new String[] {});
ComponentInfo comp200 = new ComponentInfo("type", "code", null, "comp200", empty, 20, "cont20", 200, 0, new String[] {});
ComponentInfo comp300 = new ComponentInfo("type", "code", null, "comp300", empty, 30, "cont30", 300, 0, new String[] {});
ComponentInfo[] one_comp = { comp100 };
ComponentInfo[] two_comps = { comp100, comp200 };
ComponentInfo[] three_comps = { comp100, comp200, comp300 };
ContainerInfo cont10 = new ContainerInfo("cont10", 10, null, empty);
ContainerInfo cont20 = new ContainerInfo("cont20", 20, null, empty);
ContainerInfo cont30 = new ContainerInfo("cont30", 30, null, empty);
ContainerInfo[] one_cont = { cont10 };
ContainerInfo[] two_conts = { cont10, cont20 };
ContainerInfo[] three_conts = { cont10, cont20, cont30 };
ClientInfo clientA = new ClientInfo(0, null, empty, "clientA", 0);
ClientInfo client1 = new ClientInfo(1, null, empty, "client1", 0);
ClientInfo client2 = new ClientInfo(2, null, empty, "client2", 0);
ClientInfo client3 = new ClientInfo(3, null, empty, "client3", 0);
ClientInfo[] one_client = { client1 };
ClientInfo[] two_clients = { client1, client2 };
ClientInfo[] three_clients = { client1, client2, client3 };
Mockito.when(orb.string_to_object("dummy")).thenReturn(manager);
Mockito.when(manager.login(administrator)).thenReturn(clientA);
Mockito.when(manager.get_component_info(hhhhh, empty, "*", "*", false)).thenReturn(one_comp, two_comps, three_comps);
Mockito.when(manager.get_container_info(hhhhh, empty, "*")).thenReturn(one_cont, one_cont, two_conts, three_conts);
Mockito.when(manager.get_client_info(hhhhh, empty, "*")).thenReturn(one_client, two_clients, three_clients, two_clients, three_clients);
// make the supervisor
// -----------------------------------------------------------------
log = new Logger("Test", null) {
final long start = System.nanoTime();
@Override
public void log(LogRecord r) {
long sinceStart = (System.nanoTime() - start) / 1000 / 1000 / 1000;
System.out.println(String.format("%2d", sinceStart) + " " + r.getLevel() + " " + r.getMessage());
}
};
log.setLevel(Level.FINE);
testee = new MaciSupervisor("Test", "dummy", orb, log);
testee.acImpl = testee.new AdministratorImplementation() {
@Override
protected Administrator asCorbaObject(ORB orb) {
return administrator;
}
};
testee.start();
// assertions
// ----------------------------------------------------------------
maciListener = new MaciInfoListener();
MaciInfo maciInformation = testee.getMaciInformation();
maciInformation.addTreeModelListener(maciListener);
}
use of si.ijs.maci.ClientInfo in project ACS by ACS-Community.
the class AcsManagerProxy method loginToManager.
/**
* Logs in to the Manager.
* Only to be called from within this class (see connectorThread), when the
*
* @param attempts The number of attempts to contact the manager (0 means forever)
* used for the call to {@link #findManager(String, int)}
* @throws AcsJContainerServicesEx
*/
private synchronized void loginToManager(int attempts) throws AcsJContainerEx {
if (m_shuttingDown) {
String msg = "call to loginToManager(..) fails while shutting down.";
m_logger.fine(msg);
AcsJContainerEx ex = new AcsJContainerEx();
ex.setContextInfo(msg);
throw ex;
}
if (isLoggedIn(false)) {
m_logger.info("login to Manager requested while being logged in - will first log out...");
logoutFromManager();
}
if (m_manager == null) {
m_logger.fine("manager reference not yet available in method loginToManager; " + "will try to find the manager first...");
findManager(m_managerLoc, attempts);
}
try {
// login
ClientInfo ci = m_manager.login(m_managerClient);
if (ci == null) {
throw new NullPointerException("received null from manager.login()");
}
if (ci.h <= 0) {
AcsJContainerEx ex = new AcsJContainerEx();
ex.setContextInfo("Got invalid handle from manager login: " + ci.h);
throw ex;
}
m_mgrHandle = ci.h;
} catch (Throwable thr) {
m_mgrHandle = 0;
String msg = "Failed to login to manager.";
m_logger.log(Level.WARNING, msg);
AcsJContainerEx ex = new AcsJContainerEx(thr);
ex.setContextInfo(msg);
throw ex;
}
m_logger.fine("Manager login done, handle '" + m_mgrHandle + "' obtained.");
}
use of si.ijs.maci.ClientInfo in project ACS by ACS-Community.
the class SimpleMasterComponentTest method test.
/**
* Main test routine.
*/
public void test() {
initializeCORBA();
Manager manager = resolveManager();
if (manager != null) {
ClientInfo clientInfo = login(manager);
if (clientInfo != null) {
System.out.println("All initialization done.");
//
// get component
//
final String COMPONENT_NAME = "SIMPLEMASTERCOMPONENT1";
org.omg.CORBA.Object obj;
try {
obj = manager.get_component(clientInfo.h, COMPONENT_NAME, true);
SimpleMasterComponent simpleMasterComponent = SimpleMasterComponentHelper.narrow(obj);
ROstringSeq currentStateHierarchy = simpleMasterComponent.currentStateHierarchy();
// syncvalue retrival
System.out.println("Current state hierarchy: " + getStringArray(currentStateHierarchy.get_sync(new CompletionHolder())));
System.out.println("Monitoring - 1s interval...");
// create a monitor
MonitorstringSeq monitor = currentStateHierarchy.create_monitor(new CBstringSeqImpl()._this(orb), new CBDescIn());
// sleep for a while
try {
Thread.sleep(10000);
} catch (InterruptedException ie) {
}
;
monitor.set_timer_trigger(0);
monitor.set_value_trigger(new String[0], true);
System.out.println("On-change monitoring...");
// sleep for a while
try {
Thread.sleep(10000);
} catch (InterruptedException ie) {
}
;
monitor.destroy();
} catch (Exception e) {
// CannotGetComponentEx, ComponentConfigurationNotFoundEx
System.err.println("Failed to obtain component: " + COMPONENT_NAME);
}
// release now
try {
manager.release_component(clientInfo.h, COMPONENT_NAME);
} catch (NoPermissionEx ex) {
ex.printStackTrace();
}
logout(manager, clientInfo);
}
}
finalizeCORBA();
}
use of si.ijs.maci.ClientInfo in project ACS by ACS-Community.
the class DeserializeManagerFromFile method main.
/**
* @param args
*/
public static void main(String[] args) throws Throwable {
File f = new File(args[0]);
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(f));
// we cast directly to the implementation
ManagerImpl manager = (ManagerImpl) obj.readObject();
{
//
// list all active components
//
HandleDataStore components = manager.getComponents();
System.out.println("Capacity of handle data store: " + components.capacity());
System.out.println(components.size() + " component(s) stored:");
int h = components.first();
while (h != 0) {
ComponentInfo componentInfo = (ComponentInfo) components.get(h);
System.out.println("\tName : " + componentInfo.name);
System.out.println("\tHandle : " + componentInfo.h + ", " + HandleHelper.toString(componentInfo.h));
System.out.println("\tType : " + componentInfo.type);
System.out.println("\tCode : " + componentInfo.code);
System.out.println("\tContainer name : " + componentInfo.container_name);
System.out.println("\tContainer handle: " + HandleHelper.toString(componentInfo.container));
System.out.println("\tClients : count = " + componentInfo.clients.length);
for (int j = 0; j < componentInfo.clients.length; j++) System.out.println("\t \t" + componentInfo.clients[j]);
System.out.println("\t-------------------------------");
h = components.next(h);
}
}
System.out.println();
System.out.println();
System.out.println();
{
//
// list all active containers
//
HandleDataStore containers = manager.getContainers();
System.out.println("Capacity of handle data store: " + containers.capacity());
System.out.println(containers.size() + " container(s) returned:");
int h = containers.first();
while (h != 0) {
ContainerInfo containersInfo = (ContainerInfo) containers.get(h);
System.out.println("\tName : " + containersInfo.name);
System.out.println("\tHandle : " + containersInfo.h + ", " + HandleHelper.toString(containersInfo.h));
System.out.println("\tComponents : count = " + containersInfo.components.length);
for (int j = 0; j < containersInfo.components.length; j++) System.out.println("\t \t" + containersInfo.components[j]);
System.out.println("\t-------------------------------");
}
}
System.out.println();
System.out.println();
System.out.println();
{
//
// list all active clients
//
HandleDataStore clients = manager.getClients();
System.out.println("Capacity of handle data store: " + clients.capacity());
System.out.println(clients.size() + " clients(s) returned:");
int h = clients.first();
while (h != 0) {
ClientInfo clientsInfo = (ClientInfo) clients.get(h);
System.out.println("\tName : " + clientsInfo.name);
System.out.println("\tHandle : " + clientsInfo.h + ", " + HandleHelper.toString(clientsInfo.h));
System.out.println("\tComponents : count = " + clientsInfo.components.length);
for (int j = 0; j < clientsInfo.components.length; j++) System.out.println("\t \t" + clientsInfo.components[j]);
System.out.println("\t-------------------------------");
}
}
System.out.println();
System.out.println();
System.out.println();
{
//
// list all active administrators
//
HandleDataStore clients = manager.getAdministrators();
System.out.println("Capacity of handle data store: " + clients.capacity());
System.out.println(clients.size() + " administrators(s) returned:");
int h = clients.first();
while (h != 0) {
ClientInfo clientsInfo = (ClientInfo) clients.get(h);
System.out.println("\tName : " + clientsInfo.name);
System.out.println("\tHandle : " + clientsInfo.h + ", " + HandleHelper.toString(clientsInfo.h));
System.out.println("\tComponents : count = " + clientsInfo.components.length);
for (int j = 0; j < clientsInfo.components.length; j++) System.out.println("\t \t" + clientsInfo.components[j]);
System.out.println("\t-------------------------------");
}
}
System.out.println();
System.out.println();
System.out.println();
System.out.println("# of unavailable components in a map: " + manager.getUnavailableComponents().size());
System.out.println("# of default components in a map: " + manager.getDefaultComponents().size());
System.out.println("# of active alarms in a map: " + manager.getActiveAlarms().size());
System.out.println("# of released handles in a map: " + manager.getReleasedHandles().size());
}
use of si.ijs.maci.ClientInfo in project ACS by ACS-Community.
the class DumpManagerState method login.
/**
* Login to the manager.
* @param manager manager reference.
* @return client info, <code>null</code> on failure.
*/
private ClientInfo login(Manager manager) {
if (orb == null || manager == null)
return null;
System.out.println("Logging to the manager...");
try {
ClientImpl clientImpl = new ClientImpl();
Client client = clientImpl._this(orb);
ClientInfo info = manager.login(client);
if (info == null)
throw new Exception("Failed to login to the manager since returned ClientInfo is 'null'.");
System.out.println("Logged in to the manager.");
return info;
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Failed to login to the manager.");
return null;
}
}
Aggregations