OSS рдореЗрдВ NotificationIRP рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рджреБрд░реНрдШрдЯрдирд╛рдПрдВ рд╣реЛ рд░рд╣реА рд╣реИрдВ

рдирдорд╕реНрддреЗ рдкрд┐рдЫрд▓реЗ рдкреНрд░рдХрд╛рд╢рди рдореЗрдВ , рдЕрд▓рд╛рд░реНрдордЖрдИрдЖрд░рдкреА рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рд╕рдХреНрд░рд┐рдп рдЕрд▓рд╛рд░реНрдо рдкреНрд░рд╛рдкреНрдд рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдПрдХ рд╡рд┐рдзрд┐ рдкрд░ рд╡рд┐рдЪрд╛рд░ рдХрд┐рдпрд╛ рдЧрдпрд╛ рдерд╛ред рдЗрд╕рдХреЗ рдмрд╛рдж, рд╣рдо рджреЗрдЦреЗрдВрдЧреЗ рдХрд┐ рдиреЛрдЯрд┐рдлрд┐рдХреЗрд╢рди рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддреЗ рд╣реБрдП рдЕрд▓рд╛рд░реНрдо рдХреИрд╕реЗ рдкреНрд░рд╛рдкреНрдд рдХрд░реЗрдВред рдЙрджрд╛рд╣рд░рдг рдореЗрдВ, рд╣рдо NetAct Nokia рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░реЗрдВрдЧреЗред

рдЕрд▓рд╛рд░реНрдордЖрдИрдЖрд░рдкреА рдХреЗ рд╕рд╛рде рддреБрд▓рдирд╛ рдореЗрдВ, рдЗрд╕ рд▓реЗрдЦ рдореЗрдВ рд╡рд┐рдЪрд╛рд░ рдХрд┐рдП рдЧрдП рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдХреЛ рд╣рдореЗрдВ рдПрдХ рдХреЙрд░реНрдм рдХреНрд▓рд╛рдЗрдВрдЯ рдмрдирд╛рдиреЗ рдХреЗ рдЕрд▓рд╛рд╡рд╛, "рдХреЙрд░реНрдм рд╕рд░реНрд╡рд░" рдмрдирд╛рдиреЗ рдХреА рднреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реЛрдЧреА, рдЬреЛ рдиреЛрдЯрд┐рдлрд┐рдХреЗрд╢рдирдкреАрдЖрд░ рд╕реЗ рд╕рдВрджреЗрд╢реЛрдВ рдХреЛ рдкреНрд░реЛрд╕реЗрд╕ рдХрд░реЗрдЧрд╛ред рдпрд╣ "рд╕рд░реНрд╡рд░", рдЕрдиреНрдп рдмрд╛рддреЛрдВ рдХреЗ рдЕрд▓рд╛рд╡рд╛, рдкреБрд╢_рд╕реНрдЯреНрд░рдХреНрдЪрд░_рд╡реЗрдЬрд╝ рдкрджреНрдзрддрд┐ рдХреЛ рд▓рд╛рдЧреВ рдХрд░рдирд╛ рдЪрд╛рд╣рд┐рдП, рдЬрд┐рд╕рдореЗрдВ рдУрдПрд╕рдПрд╕ рд╕реНрдЯреНрд░рдХреНрдЪрд░реНрдбрдПрд╡реЗрдВрдЯ [] рдХреЗ рд░реВрдк рдореЗрдВ рдШрдЯрдирд╛рдУрдВ рдХреЛ рдкреНрд░рд╕рд╛рд░рд┐рдд рдХрд░реЗрдЧрд╛ред рдРрд╕рд╛ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, рд╣рдореЗрдВ рдирд┐рдореНрди рд╡рд░реНрдЧ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИ:

private class IRPManager extends org.omg.CosNotifyComm.SequencePushConsumerPOA{ @Override public void push_structured_events(StructuredEvent[] notifications) throws org.omg.CosEventComm.Disconnected { for (StructuredEvent alarm: notifications) { alarmPrint(alarm); } } @Override public void offer_change(EventType[] arg0, EventType[] arg1) throws org.omg.CosNotifyComm.InvalidEventType { System.out.println("Offer Change!"); } @Override public void disconnect_sequence_push_consumer() { System.out.println("Disconnected!"); } } 

рдЕрд▓рд╛рд░реНрдордкреНрд░рд┐рдВрдЯ рд╡рд┐рдзрд┐ рдкрд┐рдЫрд▓реЗ рд▓реЗрдЦ рд╕реЗ рдПрдХ рд╣реА рдирд╛рдо рдХреЗ рд╕рдорд╛рди рд╣реИред рдЕрдВрдд рдореЗрдВ, рдкреВрд░реЗ рдкреНрд░реЛрдЬреЗрдХреНрдЯ рдХрд╛ рдкреВрд░рд╛ рдХреЛрдб рд╕рдВрд▓рдЧреНрди рдХрд┐рдпрд╛ рдЬрд╛рдПрдЧрд╛ред

рдЕрдм рдЖрдкрдХреЛ рдУрдЖрд░рдмреА рд╕рд░реНрд╡рд░ рдХреА рдХрд╛рд░реНрдпрдХреНрд╖рдорддрд╛ рдХреЗ рд╕рд╛рде рдЗрд╕ рд╡рд░реНрдЧ рдХреЛ "рд░реИрдк" рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИ, рдиреЛрдЯрд┐рдлрд┐рдХреЗрд╢рдирдкреА рдкреНрд░рд╛рдкреНрдд рдХрд░реЗрдВ рдФрд░ рдЗрд╕реЗ рдкреНрд░рд╛рдкреНрдд рд╡рд╕реНрддреБ рдХреЗ рд▓рд┐рдП рдПрдХ рд▓рд┐рдВрдХ рджреЗрдВред

 _irpMan = new IRPManager(); _notificationOrb = ORB.init(new String[0], null); org.omg.CORBA.ORB orb = ORB.init(new String[0], null); org.omg.CORBA.Object rootObj = orb.string_to_object(readIOR()); _notifIrp = com.nsn.oss.nbi.internal.corba.NotificationIRPSystem.NotificationIRPHelper.narrow(rootObj); POA poa; poa = POAHelper.narrow(_notificationOrb.resolve_initial_references("RootPOA")); poa.the_POAManager().activate(); _notifySrvr = poa.servant_to_reference(_irpMan); _notifyServer = _notificationOrb.object_to_string(_notifySrvr); //     String[] aCat = _notifIrp.get_notification_categories(new NotificationTypesSetHolder()); StringTypeOpt alarmFltr = new StringTypeOpt(); alarmFltr.value(alarmFilter); //   _attId = _notifIrp.attach_push(_notifyServer, timetick, aCat, alarmFltr, ""); // ORB   (new notificationThread()).start(); 

ORB рдЪрд▓рд╛рдиреЗ рдХреЗ рд▓рд┐рдП рд╣рдо рдПрдХ рдЙрдкрдкреНрд░рдХрд╛рд░ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░реЗрдВрдЧреЗ:
 private class notificationThread extends Thread { public void run() { _notificationOrb.run(); } } 

рд╕рдордпрд╕реАрдорд╛ рд╕рдорд╛рдкреНрдд рд╣реЛрдиреЗ рдХреЗ рдмрд╛рдж, рдпрд╛ рдЬрдм рддрдХ рд╣рдо рдЗрд╕реЗ рдЕрд▓рдЧ рдирд╣реАрдВ рдХрд░рддреЗ, рддрдм рддрдХ OSS рд╣рдореЗрдВ рд╕реВрдЪрдирд╛рдПрдВ рднреЗрдЬрдирд╛ рдмрдВрдж рдХрд░ рджреЗрдЧрд╛ред рдпрджрд┐ рд╣рдореЗрдВ рдЯрд╛рдЗрдорд░ рд╕рдорд╛рдкреНрдд рд╣реЛрдиреЗ рдХреЗ рдмрд╛рдж рд╕рдВрджреЗрд╢ рдкреНрд░рд╛рдкреНрдд рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИ, рддреЛ рд╣рдореЗрдВ get_subscription_status рдкрджреНрдзрддрд┐ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рд╕рд┐рд╕реНрдЯрдо рдХреЛ рдЗрд╕рдХреА рд░рд┐рдкреЛрд░реНрдЯ рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИред рдЬрдм рдпрд╣ рдХрд╣рд╛ рдЬрд╛рддрд╛ рд╣реИ, рдЯрд╛рдЗрдорд░ рдлрд┐рд░ рд╕реЗ рдЙрд▓рдЯреА рдЧрд┐рдирддреА рд╢реБрд░реВ рдХрд░ рджреЗрдЧрд╛ред
рдпрд╣ рд╕рдм рдХреБрдЫ рдПрдХ рд╕рд╛рде рдЗрдХрдЯреНрдард╛ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд░рд╣рддрд╛ рд╣реИ, рдиреЗрдЯрдПрдХреНрдЯ рдореЗрдВ рдЖрд╡рд╢реНрдпрдХ рдкреБрд╕реНрддрдХрд╛рд▓рдпреЛрдВ рдХреЛ рдвреВрдВрдвреЗрдВ рдФрд░ рдЙрд╕ рд╡рд░реНрдЪреБрдЕрд▓ рдорд╢реАрди рд╕реЗ рдХрдиреЗрдХреНрдЯ рдХрд░реЗрдВ рдЬрд┐рд╕ рдкрд░ nbi3gc рд╕рд░реНрд╡рд░ рдЪрд▓ рд░рд╣рд╛ рд╣реИ (IOR рдЗрд╕ рдЙрджрд╛рд╣рд░рдг рд╕реЗ рд╣рдо рдлрд╝рд╛рдЗрд▓ рд╕реЗ рдкрдврд╝ рд░рд╣реЗ рд╣реИрдВ)ред рдкреНрд░рд╕реНрддрд╛рд╡рд┐рдд рдЙрджрд╛рд╣рд░рдг рдХреЛ рдЪрд▓рд╛рдиреЗ рдХреЗ рд▓рд┐рдП, рд╣рдо рдХрдорд╛рдВрдб рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░реЗрдВрдЧреЗ:
java -cpред: рдЬрдХреЛрд░реНрдм-3.1.рдЬрд░: рдЬрдХреЛрд░реНрдм-рд╕рд░реНрд╡рд┐рд╕реЗрдЬ-3.1.рдЬрд░: nbi3gc-internal-corba-interface-17.8.0.158.jar AlarmClient

рд╕реНрдкреЙрдЗрд▓рд░ рдХреЗ рддрд╣рдд, рдкреВрд░реНрдг рдЙрджрд╛рд╣рд░рдг рдХреЛрдб
 import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import org.omg.CORBA.IntHolder; import org.omg.CORBA.ORB; import org.omg.CORBA.ORBPackage.InvalidName; import org.omg.CosNotification.EventType; import org.omg.CosNotification.Property; import org.omg.CosNotification.StructuredEvent; import org.omg.PortableServer.POA; import org.omg.PortableServer.POAHelper; import org.omg.PortableServer.POAManagerPackage.AdapterInactive; import org.omg.PortableServer.POAPackage.ServantNotActive; import org.omg.PortableServer.POAPackage.WrongPolicy; import org.omg.TimeBase.UtcT; import org.omg.TimeBase.UtcTHelper; import com.nsn.oss.nbi.internal.corba.ManagedGenericIRPConstDefs.StringTypeOpt; import com.nsn.oss.nbi.internal.corba.ManagedGenericIRPConstDefs.StringTypeOptHolder; import com.nsn.oss.nbi.internal.corba.ManagedGenericIRPSystem.InvalidParameter; import com.nsn.oss.nbi.internal.corba.ManagedGenericIRPSystem.OperationNotSupported; import com.nsn.oss.nbi.internal.corba.ManagedGenericIRPSystem.ParameterNotSupported; import com.nsn.oss.nbi.internal.corba.NotificationIRPConstDefs.NotificationTypesSetHolder; import com.nsn.oss.nbi.internal.corba.NotificationIRPSystem.GetNotificationCategories; public class AlarmClient { private com.nsn.oss.nbi.internal.corba.NotificationIRPSystem.NotificationIRP _notifIrp = null; public String alarmFilter =""; private final long UNIX_OFFSET = 122192928000000000L; public String delimiter = ";"; private org.omg.CORBA.ORB _notificationOrb = null; private String _notifyServer = null; private org.omg.CORBA.Object _notifySrvr = null; private String _attId = ""; private IRPManager _irpMan = null; public int timetick = 15; public static void main(String[] args) { AlarmClient ac = new AlarmClient(); ac.startNotifications(); try { Thread.sleep(20000); } catch (InterruptedException e) { e.printStackTrace(); } ac.stopNotifications(); } private String readIOR(String iorType) { File f = new File("/d/oss/global/var/NSN-nbi3gc/ior/NotificationIRP.ior"); BufferedReader br; String iorContents = null; try { br = new BufferedReader(new FileReader(f)); iorContents = br.readLine(); br.close(); } catch (IOException e) { e.printStackTrace(); } return iorContents; } private void alarmPrint(StructuredEvent alarm){ String result = ""; UtcT timeValue = null; Date dt; DateFormat df; if (alarm.filterable_data != null) { for (Property filterableData: alarm.filterable_data) { String fieldName = filterableData.name; switch (fieldName){ case "b": timeValue = UtcTHelper.extract(filterableData.value); dt = new Date((timeValue.time - UNIX_OFFSET) / 10000); df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); result = result + df.format(dt) + delimiter; break; case "e": result = result + filterableData.value.extract_string() + delimiter; break; case "i": result = result + filterableData.value.extract_string() + delimiter; break; } } } System.out.println(result); } public void startNotifications(){ _irpMan = new IRPManager(); _notificationOrb = ORB.init(new String[0], null); org.omg.CORBA.ORB orb = ORB.init(new String[0], null); org.omg.CORBA.Object rootObj = orb.string_to_object(readIOR("NotificationIRP")); _notifIrp = com.nsn.oss.nbi.internal.corba.NotificationIRPSystem.NotificationIRPHelper.narrow(rootObj); POA poa; try { poa = POAHelper.narrow(_notificationOrb.resolve_initial_references("RootPOA")); poa.the_POAManager().activate(); _notifySrvr = poa.servant_to_reference(_irpMan); _notifyServer = _notificationOrb.object_to_string(_notifySrvr); String[] aCat = _notifIrp.get_notification_categories(new NotificationTypesSetHolder()); StringTypeOpt alarmFltr = new StringTypeOpt(); alarmFltr.value(alarmFilter); _attId = _notifIrp.attach_push(_notifyServer, timetick, aCat, alarmFltr, ""); (new notificationThread()).start(); } catch (InvalidName | AdapterInactive | ParameterNotSupported | com.nsn.oss.nbi.internal.corba.NotificationIRPSystem.AtLeastOneNotificationCategoryNotSupported | InvalidParameter | com.nsn.oss.nbi.internal.corba.NotificationIRPSystem.Attach | com.nsn.oss.nbi.internal.corba.NotificationIRPSystem.AlreadySubscribed | ServantNotActive | WrongPolicy | GetNotificationCategories | OperationNotSupported e) { e.printStackTrace(); } } public void stopNotifications() { try { _notifIrp.detach(_notifyServer, _attId); _notificationOrb.shutdown(true); } catch (com.nsn.oss.nbi.internal.corba.NotificationIRPSystem.DetachException | ParameterNotSupported | InvalidParameter e) { e.printStackTrace(); } } public int renewSubscription() { com.nsn.oss.nbi.internal.corba.NotificationIRPConstDefs.SubscriptionStateHolder arg2 = new com.nsn.oss.nbi.internal.corba.NotificationIRPConstDefs.SubscriptionStateHolder(); IntHolder arg3 = new IntHolder(); StringTypeOptHolder arg1 = new StringTypeOptHolder(); arg1.value.value(alarmFilter); try { _notifIrp.get_subscription_status(_attId, arg1, arg2, arg3); } catch (InvalidParameter | com.nsn.oss.nbi.internal.corba.ManagedGenericIRPSystem.OperationNotSupported | com.nsn.oss.nbi.internal.corba.NotificationIRPSystem.GetSubscriptionStatus e) { e.printStackTrace(); } return arg2.value.value(); } private class IRPManager extends org.omg.CosNotifyComm.SequencePushConsumerPOA{ @Override public void push_structured_events(StructuredEvent[] notifications) throws org.omg.CosEventComm.Disconnected { for (StructuredEvent alarm: notifications) { alarmPrint(alarm); } } @Override public void offer_change(EventType[] arg0, EventType[] arg1) throws org.omg.CosNotifyComm.InvalidEventType { System.out.println("Offer Change!"); } @Override public void disconnect_sequence_push_consumer() { System.out.println("Disconnected!"); } } private class notificationThread extends Thread { public void run() { _notificationOrb.run(); } } } 

рдЖрдкрдХрд╛ рдзреНрдпрд╛рди рдХреЗ рд▓рд┐рдП рдзрдиреНрдпрд╡рд╛рджред рдпрд╣ рд╕рдВрдХреНрд╖реЗрдк рдореЗрдВ рдирд┐рдХрд▓рд╛, рд▓реЗрдХрд┐рди, рдореЗрд░реА рд░рд╛рдп рдореЗрдВ, рдореБрдЦреНрдп рдмрд┐рдВрджреБрдУрдВ рдкрд░ рд╡рд┐рдЪрд╛рд░ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ, рдореБрдЭреЗ рдЙрдореНрдореАрдж рд╣реИ рдХрд┐ рдпрд╣ рдЬрд╛рдирдХрд╛рд░реА рдЙрдкрдпреЛрдЧреА рд╣реЛрдЧреАред рдкреНрд░рд╢реНрдиреЛрдВ рдФрд░ рдЯрд┐рдкреНрдкрдгрд┐рдпреЛрдВ рдХрд╛ рд╕реНрд╡рд╛рдЧрдд рд╣реИред

Source: https://habr.com/ru/post/hi423583/


All Articles