cc/td/doc/product/rtrmgmt/cpc
hometocprevnextglossaryfeedbacksearchhelp
PDF

Table of Contents

CORBA Tutorial

CORBA Tutorial

This chapter provides a basic tutorial for using the CORBA interface with CPC. This chapter assumes that the reader has an advanced level of knowledge about CORBA.

Writing a CPC CORBA Client

This section walks through the basics of writing an CPC CORBA Client. This includes a discussion of the following areas:

Three complete examples are provided at the end of this chapter that can be compiled and executed.

Comparison to Script Language

Table 4-1 lists the corresponding Script Language commands and CORBA methods.


Table 4-1: Script Language Commands and CORBA Methods
Area Script Language Command CORBA Method

Session Management

AVtm

SessionFactory, Session

Transaction Management

AVcr

TransactionManager

Service Object Management

com.syndesis.activator.
Activator

ServiceObjectManager

NNI Resiliency Manager

com.syndesis.resiliency.

ServiceUtility

NNIResiliencyManager

UNI Resiliency Manager

com.syndesis.resiliency.

ServiceUtility

UNIResiliencyManager

Configuration Object Management

nps

NetworkElementFactory, Network Element, PersistentFactory, Persistent, Lister, SiteItemLister, UploadRequestFactory, UploadRequest

Event Management

(no Script Language equivalent)

EventSourceFactory, EventSource

Miscellaneous

(no Script Language equivalent)

MetaDataServer, LogFileServer

Typical Client Program Flow

All CPC CORBA operations are performed in the context of a session. Within a session, CORBA requests are processed one at a time (single-threaded model). CORBA requests made to different sessions are processed in parallel. A session is shut down when a specific request is made to remove it, or when there are not any CORBA clients connected to it. Figure 4-1 illustrates the typical client program flow.


Figure 4-1: Client Program Flow


CORBA Name Server Usage

The naming service enables CORBA objects to register and be located by name. CPC uses a single naming context named nptSessionRoot in the naming service root context. Under this context, there is a context for each workstation running an CPC CORBA server. The name of the context is the same as the name of the workstation. Under each workstation context, there are one or two factory objects registered named AVSessionFactory and SYSessionFactory. The object named AVSessionFactory is the CPC session factory and implements the SYcrbAV::SessionFactory interface. This is the object used by a client application to create a session. The object named SYSessionFactory is normally not used by a client application.

A unique naming context is associated with each session. It holds object references to the managers and factories for that session. The client application should obtain the session unique naming context from the session, it should not rely on the context being at a particular position within the naming context hierarchy.


Figure 4-2: Name Server Usage


SessionFactory and Session IDL

The SessionFactory and Session interfaces that should be used by a client application are defined in the SYcrbAV module. These interfaces are derived from SessionFactory and Session interfaces defined in the SYcrbNPT module.

SessionFactory::createMaster() is used to create a new session. The 'userName' input parameter determines the access privileges available within the session. A userName of superUser allows unrestricted access. The SessionFactory::attachMaster() and SessionFactory::attachMasterL() methods allows CORBA access to an existing script or GUI session. The existing session can be specified as either an object id (SYssnSession:n) or as a session number. A session is released by invoking the Session:remove() method. If the session was the result of an attach, script or GUI access to the session may continue after remove has been called.

The session unique naming context is obtained from the session using the Session::getServices() method.

module SYcrbAV {
  interface SessionFactory :  SYcrbNPT::SessionFactory {};
  interface Session        :  SYcrbNPT::Session        {};
}; 
 
module SYcrbNPT { 
  interface SessionFactory {
   Session  createMaster   (in string userName, 
                             in string sessionType)  raises(NptException);
   Session  attachMaster   (in ObjectId sessionId)  raises(NptException);
   Session  attachMasterL  (in long sessionId)      raises(NptException);
  };
 
   interface Session {
   CosNaming::NamingContext  getServices  ();
   long                   getSessionId ();
   PersistentId           getOpenCR    ()        raises(NptException);
   void                    remove       ();
   };
};

Starting a Session

System.out.println("initialize ORB");
org.omg.CORBA.ORB orb = IE.Iona.OrbixWeb.CORBA.ORB.init();
 
System.out.println("get root naming service context");
org.omg.CORBA.Object tempObj = orb.resolve_initial_references("NameService");
NamingContext rootContext = NamingContextHelper.narrow(tempObj);
 
System.out.println("get Activator session factory object");
NameComponent name = new NameComponent[3];
name[0]            = new NameComponent("nptSessionRoot",   "");
name[1]            = new NameComponent("opal",             "");
name[2]            = new NameComponent("AVSessionFactory", "");
tempObj = rootContext.resolve(name);
SessionFactory sessionFactory = SessionFactoryHelper.narrow(tempObj);
 
System.out.println("create a new session");
Session session = SessionHelper.narrow(sessionFactory.createMaster("superUser",                                                           ""));
 
System.out.println("get session services naming context");
NamingContext sessionServicesContext = session.getServices();

Session Naming Context Contents

The session unique naming context contains the managers and factories for the session. Unlike the Script Language where the session number is provided as a parameter to every command, the session is determined implicitly by the manager or factory object when one of its methods is invoked.

The naming context contains the objects shown in the table below. Other objects may exist in the naming context that are provided by NPT but are not used by CPC. These objects should be ignored. The number of objects in the naming context implementing the 'SYcrbAV::ServiceObjectManager' interface will depend on the number of CPC Service Applications installed in the system. A ServiceObjectManager object will exist for each type of service installed.


Table 4-2: Session Network Context
Object Name Interface Implemented

transactionManager

TransactionManager

com.syndesis.frrm.RAsvServiceObject

ServiceObjectManager

com.syndesis.frrm.RFsvServiceObject

ServiceObjectManager

com.syndesis.frrm.RFixServiceObject

ServiceObjectManager

com.syndesis.scb.SCB1CBR

ServiceObjectManager

com.syndesis.scb.SCB3CES

ServiceObjectManager

com.syndesis.sdl.SDLProvider

ServiceObjectManager

com.syndesis.sdl.SDLPsd

ServiceObjectManager

com.syndesis.sdl.SDLPap

ServiceObjectManager

com.syndesis.sdl.SDLPad

ServiceObjectManager

com.syndesis.sdl.SDLSubscriber

ServiceObjectManager

com.syndesis.sdl.SDLSubscConnection

ServiceObjectManager

com.syndesis.sdl.SDLL3Conn

ServiceObjectManager

com.syndesis.sdl.SDLL2TPSap

ServiceObjectManager

com.syndesis.sdl.SDLLANSap

ServiceObjectManager

com.syndesis.scb.SBR1Vlanc

ServiceObjectManager

com.syndesis.scb.SBRTATMcnx

ServiceObjectManager

com.syndesis.scb.SBRVATMIW

ServiceObjectManager

com.syndesis.scb.SBRFFRcnx

ServiceObjectManager

com.syndesis.scb.SBRHFRIW

ServiceObjectManager

com.syndesis.resiliency.NNIResiliency

NNIResiliencyManager

com.syndesis.resiliency.UNIResiliency

UNIResiliencyManager

networkElementFactory

NetworkElementFactory

uploadRequestFactory

UploadRequestFactory

persistentFactory

PersistentFactory

eventSourceFactory

EventSourceFactory

metaDataServer

MetaDataServer

logFileServer

LogFileServer

Service Object Commands

There is a one-to-one mapping between Service Object commands provided by the Script Language interface and methods provided by the ServiceObjectManager interface. The mapping of Script Language command to CORBA method name is shown in the table below. Unless specifically documented for a particular Service Application, the ServiceObjectManager::genericRequest() method provides no functionality

.
Table 4-3: Service Object Commands
Script Language Command ServiceObjectManagerMethod

create

create

modify

modify

delete

del

view

getAllAttributes

viewWithModes

getAllAttributesWithModes

details

getDetails

list

listAllAttributes

viewProfile

getAllProfileAttributes

listProfile

listAllProfileAttributes

(no Script Language equivalent)

genericRequest

ServiceObjectManager::create

The input and output parameters to ServiceObjectManager methods are equivalent to the Script Language command line parameters, but are encoded differently. As an example, the ServiceObjectmanager::create() method is shown below. The transactionMode parameter is equivalent to the AVcr= command line parameter. When transactionMode is set to Specified, the transactionId parameter must contain the object id of the transaction to be used (SYcadChangeOrder:n). The transactionAttributes sequence contains attributes to be used when a transaction is created by the service object (Atomic and Auto modes). The transaction attributes supported are: briefdescription, domain, vpn. The input soAttributes are the same service object attributes specified through the command line.

The object id of the created service object is returned. All the service object attributes are also returned through the soAttributes inout parameter. The object id of the transaction created or used is returned through the transactionId inout parameter.

If the requested service cannot be successfully created, the transaction is abandoned and an AVAutoTransactionException is thrown. In addition to error information, the object id of the abandoned transaction is provided.

enum  TransactionMode  { Atomic, Auto, Current, Open, Specified, None };
 
typedef  SYcrbNPT::PersistentId  CRID;
typedef  SYcrbNPT::PersistentId  SOID;
 
typedef  string  AttributeName;
typedef  string  AttributeValue;
struct AttributeValueItem {
  AttributeName   name;
  AttributeValue  value;
};
typedef  sequence<AttributeValueItem>  AttributeValueItemSeq;
 
interface ServiceObjectManager {
 
  SOID create(
    in     TransactionMode                 transactionMode,
    inout CRID                            transactionId,
    in    SYcrbNPT::AttributeValueItemSeq transactionAttributes,
    inout SYcrbNPT::AttributeValueItemSeq soAttributes)
    raises(AVAutoTransactionException);
};

Creating a Service

System.out.println("get ATM Service Object Manager");
name    = new NameComponent[1];
name[0] = new NameComponent("com.syndesis.frrm.RAsvServiceObject", "");
tempObj = sessionServicesContext.resolve(name);
ServiceObjectManager soManager = ServiceObjectManagerHelper.narrow(tempObj);
 
TransactionMode trMode = TransactionMode.Atomic;
org.omg.CORBA.StringHolder trId = new org.omg.CORBA.StringHolder();
trId.value = "";
AttributeValueItem[] trAttrs = new AttributeValueItem[1];
trAttrs[0] = new AttributeValueItem("briefdescription", "create SO");
 
AttributeValueItemSeqHolder soAttrs = new AttributeValueItemSeqHolder();
soAttrs.value    = new AttributeValueItem[4];
soAttrs.value[0] = new AttributeValueItem("a_tp",        "bpx_a./2.1");
soAttrs.value[1] = new AttributeValueItem("z_tp",        "bpx_a./2.2");
soAttrs.value[2] = new AttributeValueItem("name",        "sample SO");
soAttrs.value[3] = new AttributeValueItem("profilename", "so_gold");
 
System.out.println("create ATM Service Object");
String soid = soManager.create(trMode, trId, trAttrs, soAttrs);
System.out.println("soid="+soid);

ServiceObjectManager::getDetails

This is an example of a ServiceObjectManager method that references an existing service object. The particular service object is referenced by object id using the id input parameter. The ServiceObjectManager::getDetails() method returns attributes of the components of a service, equivalent to the Script Language details command. The results are returned as a sequence of attribute name/value pairs. Each contained sequence contains the name/value pairs for a component of the service. The transactionMode and transactionId attributes are provided so that getDetails() can be performed in the context of a specific transaction. Normally, a transactionMode of Current is used when no specific transaction is desired.

typedef  string  AttributeName;
typedef  string  AttributeValue;
struct AttributeValueItem {
  AttributeName   name;
  AttributeValue  value;
};
typedef  sequence<AttributeValueItem>  AttributeValueItemSeq;
typedef  sequence<AttributeValueItemSeq> AttributeValueItemSeqSeq;
 
interface ServiceObjectManager {
 
  void getDetails(in SOID id, 
                  in TransactionMode transactionMode,         
                  inout CRID transactionId,
		   out AttributeValueItemSeqSeq detailsAttributes)
   raises(AVAutoTransactionException);
};

Get Service Details

trMode = TransactionMode.Current;
trId.value = "";
AttributeValueItemSeqSeqHolder dHolder = new AttributeValueItemSeqSeqHolder();
 
soManager.getDetails(soid, trMode, trId, dHolder);
AttributeValueItem[][] details = dHolder.value;
 
for (int i=0; i<details.length; i++) {
   for (int j=0; j<details[i].length; j++) {
    System.out.print(details[i][j].name + "=" + details[i][j].value + " ");
   }
  System.out.println();
}

Fabric and Service Elements

The NetworkElementFactory interface is used to:

The NetworkElement interface is used to:


Figure 4-3: Fabric and Service Elements


NetworkElementFactory IDL

SYcrbNPT::NetworkElementFactory is derived from SYcrbNPT::PersistentFactory. NetworkElementFactory::createNetworkElement() is used to create a new instance of a network element. NetworkElementFactory::bindNetworkElement() is used to obtain a CORBA reference to an existing network element. The network element is identified by its persistent id or object id. For persistent objects, the terms persistent id and object id are used interchangeably. For objects that are not persistent (for example, SYcrbNPT::Lister and Session) only the term object id is used.

Normally only three of the methods defined by SYcrbNPT::PersistentFactory are used by client applications: getObjectClass(), and createLister(), and createSiteItemLister(). getObjectClass() returns the class name of an object given its object id. createLister() creates a Lister object for the specified class. CreateSiteItemLister() creates a Lister for the sites associated with the specified change request or Transaction.

interface NetworkElementFactory : PersistentFactory {
 
  NetworkElement  createNetworkElement(in ClassId nptClassName)
                                                           raises(NptException);
  NetworkElement  bindNetworkElement   (in PersistentId id) raises(NptException);
 
};
interface PersistentFactory {
 
  Persistent  createObject  (in ClassId  nptClassName)   raises(NptException);
  Persistent  bindObject    (in PersistentId  id)        raises(NptException);
 
  ClassId     getObjectClass(in PersistentId  id)        raises(NptException);
  Lister      createLister  (in ClassId  nptClassName)   raises(NptException);
 
  Lister      bindLister     (in ObjectId  id)           raises(NptException);
  SiteItemLister createSiteItemLister(in ObjectId coid)  raises(NptException);
};

Network Element Methods

The SYcrbNPT::NetworkElement interface is derived from SYcrbNPT::Managed which is derived from SYcrb::Persistent. The NetworkElement interface is used for all fabric and service elements and for service object profile and service element profile objects. The Persistent interface is used for Site and Modified objects associated with a Transaction.

A large number of methods are defined but only a few are typically used by client applications that need to create, modify, delete, upload, and inspect objects.
Table 4-4: Network Element Methods
Persistent Managed Network Element

isNew

revert

reload

getPersistentId

getPendingOperation

upLoad

setParent

getMode

getValue

setValue

getAttributes

getAttributesAndMode

getAttributesAndGuiMode

setAttributes

overwriteAttributes

setAssociationByName

setAssociationByCriteria

getPermittedActions

getReasonNotPermitted

genericRequest

integratedRequest

getTranslatedText

undo

save

remove

Creating a Logical Port

// this must be performed within a Transaction
System.out.println("get Network Element Factory");
name    = new NameComponent[1];
name[0] = new NameComponent("networkElementFactory", "");
tempObj = sessionServicesContext.resolve(name);
NetworkElementFactory neFactory = NetworkElementFactoryHelper.narrow(tempObj);
 
System.out.println("create lport");
String lportClassName = "CSalAtmLport";
NetworkElement lport  = neFactory.createNetworkElement(lportClassName);
NetworkElement pport  = findPPort("Network1", "bpx_a.", "3", "1");
 
AttributeValueItem[] lportAttrs = new AttributeValueItem[3];
lportAttrs[0] = new AttributeValueItem("srname", "syndesis1");
lportAttrs[1] = new AttributeValueItem("srnode", pport.getValue("srnode"));
lportAttrs[2] = new AttributeValueItem("srport", pport.getPersistentId());
 
lport.overwriteAttributes(lportAttrs);
AttributeErrorItemSeqHolder errHolder = new AttributeErrorItemSeqHolder();
errHolder.value = new AttributeErrorItem[0];
lport.save(errHolder);
System.out.println("lport oid="+lport.getPersistentId());

Lister IDL

SYcrbNPT::Lister objects are created using the PersistentFactory::createLister() method. A Lister allows the CPC database to be queried. Note that Lister objects are not persistent but they consume valuable resources on the CPC Server. A client application should always delete Lister objects when they are no longer needed by calling the Lister::remove() method.

enum  Operation { 
  EqualTo, Like, CaseLike, NotEqualTo, NotLike, CaseNotLike,
  GreaterThan, GreaterThanOrEqualTo, LessThan, LessThanOrEqualTo };
struct SearchItem {
    AttributeName   name;
    Operation       operation;
    AttributeValue  value;
};
typedef string AttributeResultItem;
 
interface Lister {
  void  getList  (in SearchItemSeq     searchList,
                  in AttributeItemSeq  columnList,
                  in OrderByItemSeq    orderByList,
                  in UniqueByItemSeq   uniqueByList)     raises(NptException);
  long  getCount ()                                      raises(NptException);
  void  getItems (in  long                      fromItem,
                  in  long                      toItem,
                  out AttributeItemSeq          names,
                  out AttributeResultItemSeqSeq results) raises(NptException);
  void   clearList()                                      raises(NptException);
  void   remove   ();
}; // plus other methods not listed

Lister Example - Find a Physical Port

NetworkElement findPPort(String network, String node, String slot, String port) {
  SearchItem[]  sl       = new SearchItem[4];
  sl[0] = new SearchItem("srnode.srnetwork.srname", Operation.EqualTo, network);
  sl[1] = new SearchItem("srnode.srname",           Operation.EqualTo, node);
  sl[2] = new SearchItem("srslotnumber",            Operation.EqualTo, slot);
  sl[3] = new SearchItem("srportnumber",            Operation.EqualTo, port
  String[]      columnList= new String[1];
  columnList[0]                = SY_OBJECTID_COLUMN.value; // 'sy_objectid'
  OrderByItem[] orderByList    = new OrderByItem[0];
  String[]      uniqueByList   = new String[0];
  Lister lister = neFactory.createLister("SRppPhysicalPort");
  try {
    lister.getList(searchList, columnList, orderByList, uniqueByList);
    if (lister.getCount() == 1) {
      AttributeItemSeqHolder columnListHolder = new AttributeItemSeqHolder();
      AttributeResultItemSeqSeqHolder rh = new AttributeResultItemSeqSeqHolder();
      lister.getItems(1, 1, columnListHolder, rh);
      return neFactory.bindNetworkElement(rh.value[0][0]);
    } else
       return null;
 } finally {
  lister.remove();
 }
}

Transaction Manager IDL

The SYcrbAV::TransactionManager interface corresponds to the Script Language AVcr application. In addition to the commands provided by AVcr, TransactionManager provides methods for listing and retrieving transaction attributes, including the transaction state.

interface TransactionManager {
  const string ReadyState     = "Ready";
  const string CurrentState   = "Current";
  const string ScheduledState = "Scheduled";
  const string BusyState      = "Busy";
  const string AppliedState   = "Applied";
  const string AlertState     = "Alert";
  
  CRID create(in AttributeValueItemSeq attributes)        raises(AVException);
  void open (in CRID id)        raises(AVException);
  void close (in CRID id)                                 raises(AVException);
  void close schedule (in CRID id, in string date)        raises(AVException);  
  void apply  (in CRID id) raises(AVException): 
  void abandon(in CRID id)                                raises(AVException);  
  void del    (in CRID id)                                raises(AVException); 
  void setAttributes(in CRID id, 
                     in AttributeValueItemSeq attrs)      raises(AVException);
  void getAttributes(in CRID id, in AttributeItemSeq attrsIn,
                    out AttributeValueItemSeq attrsOut)   raises(AVException);
  void getAllAttributes(in CRID id, 
                         out AttributeValueItemSeq attrs)   raises(AVException);
  void listAllAttributes(AttributeValueItemSeq criteria,
                       out AttributeValueItemSeqSeq out) raises(AVException);
};

Using Transaction Manager

System.out.println("get Transaction Manager");
name    = new NameComponent[1];
name[0] = new NameComponent("transactionManager", "");
tempObj = sessionServicesContext.resolve(name);
TransactionManager trManager = TransactionManagerHelper.narrow(tempObj);
 
String troid = null;
try {
  AttributeValueItem[] trAttrs = new AttributeValueItem[1];
  trAttrs[0] = new AttributeValueItem("briefdescription", "create LPort");
  System.out.println("start transaction");
  troid = trManager.start(trAttrs2);
 
  // create lport ...
 
  System.out.println("apply transaction");
  trManager.apply(troid);
} catch (Exception e) {
  System.out.println("lport creation unsuccessful: "+e);
  if (troid != null) {
      System.out.println("abandon transaction");
      trManager.abandon(troid);
  }
}

NNI Resiliency Manager IDL

The SYcrbAV::NNIResiliencyManger interface provides access to the NNI resiliency link fail, link recover, and link rebalance utility functions.

typedef  SYcrbNPT::PersistentId  LINKID;
 
interface NNIResiliencyManager {
  // fail a link
  void linkFail(in LINKID link) raises(AVException);
  // recover a link
  void linkRecover(in LINKID link) raises(AVException);
  // rebalance a link
  void linkRebalance(in LINKID link) raises(AVException);
};

Using NNI Resiliency Manager

System.out.println("get NNI Resiliency Manager");
name    = new NameComponent[1];
name[0] = new NameComponent("com.syndesis.resiliency.NNIResiliency", "");
tempObj = sessionServicesContext.resolve(name);
NNIResiliencyManager nrManager = NNIResiliencyManagerHelper.narrow(tempObj);
 
System.out.println("fail a link");
nrManager.linkFail("SRlnLink:1001");
 

UNI Resiliency Manager IDL

The SYcrbAV::UniResiliencyManager interface provides the access to the UNI Fail and UNI Recover functions.

typedef -SYcrbNPT::PersistentId LPORTNAME;
 
interface UNIResiliencyManager {
// uniFail
void uniFail (in LPORTNAME lportname) raises (AVException);
// uniRecover
void uniRecover (in LPORTNAME lportname) raises (AVException);

Using UNI Resiliency Manager

name   =new NameComponent[1];
name[01] =new NameComponent ("com.syndesis.resiliency.UNIResiliency", "");
 
UNIResiliencyManager nrManager = UNIResiliencyManagerHelper.narrow(tempObj):
System.out.println ("unifail")

Event Management IDL

Event management allows a client application to receive events when changes are made to objects in the CPC database. Events are delivered from CPC to the client application using Orbix Event Services. To receive events, a client must perform the following steps:

EventSource::enableEvent() can be invoked multiple times on an EventSource object in order to enable more than one type of event on the channel. The parameters to enableEvent are:

Events are sent using the SYcrbNPT::MVCEvent structure. The elements of the structure are:

struct MVCEvent {
  string       eventClass;
  string       eventType;
  ObjectIdSeq  modelIds;
  string       parameters;
};
typedef  long                     EventSourceId;
typedef  sequence<EventSourceId>  EventSourceIdSeq;
 
interface EventSourceFactory {
  EventSource createEventSource(in CosEventChannelAdmin::EventChannel channel,
                                out EventSourceId id   raises(NptException);
  void destroyEventSource(in EventSourceId id)    raises(noSuchEventSource);
  EventSource getEventSource(in EventSourceId id) raises(noSuchEventSource);
  EventSourceIdSeq getAllEventSources ();
};
 
interface EventSource {
  enum   FilterMode  { intraSession, interSession, allSession };
  void  enableEvent (in string       eventClass, 
                     in string       eventType,
                     in ObjectIdSeq  modelIds,
                     in FilterMode    filter        raises(NptException);
  void  disableEvent (in string       eventClass,
                     in string       eventType,
                     in ObjectIdSeq  modelIds,
                     in FilterMode  filter)      raises(noSuchEvent,
                                                          NptException);
  CosEventChannelAdmin::EventChannel  getEventChannel   ();
  EventSourceId                       getEventSourceId ();
};

Configuring Events

System.out.println("get event source factory");
name    = new NameComponent[1];
name[0] = new NameComponent(esFactoryName, "");
tempObj = sessionServicesContext.resolve("eventSourceFactory");
EventSourceFactory esFactory = EventSourceFactoryHelper.narrow(tempObj);
 
System.out.println("get Orbix Event Services channel manager");
ChannelManager eventChannelManager = ChannelManagerHelper.bind(
                                         "ChannelManager:ES", "opal");
 
System.out.println("create event channel");
EventChannel eventChannel = eventChannelManager.create("myec", false);
 
System.out.println("create event source");
IntHolder esId = new IntHolder();
EventSource eventSource = esFactory.createEventSource(eventChannel, esId);
 
System.out.println("create push consumer");
PushConsumerImpl myPushConsumer = new PushConsumerImpl();
 
System.out.println("connect push consumer to event channel");
ProxyPushSupplier pps = eventChannel.for_consumers().obtain_push_supplier();
pps.connect_push_consumer(myPushConsumer);
 
System.out.println("enable all transaction and upload events");
String[] modelId = { "SYcadChangeOrder:0", "SYuplUploadRequest:0" };
eventSource.enableEvent("*", "*", modelId, FilterMode.intraSession);

Receiving Events

class PushConsumerImpl extends _PushConsumerImplBase {
  public PushConsumerImpl() {}
  public void push(Any theAny) {
  try {
      if (theAny.type().equal(MVCEventHelper.type())) {
       MVCEvent event = MVCEventHelper.extract(theAny);
 
        System.out.print("Event "+eventCount+": class="+event.eventClass);
        System.out.print(" type="+event.eventType+" model=[ ");
        for (int i=0; i<event.modelIds.length; i++)
          System.out.print(event.modelIds[i]+" ");
          System.out.println("] parameters="+event.parameters);
      } 
     } catch (Exception e) {
       System.err.println("Unexpected exception in push consumer: "+e);
    }
  }
    public void disconnect_push_consumer() {}
} 

Ending a Session

session.remove ();

Complete Examples

The examples are built on the example code shown in the previous sections.

Three complete example are provided:

All 3 examples access the CORBA Naming Service and use the CPC SessionFactory to create a session.

All examples assume that CPC is running on a Server named "opal".

sample.java

This example assumes that the CS Equipment Module and the ATM Service Application are installed. Furthermore, it assumes that a CS Network named 'Network1' exists and it contains a BPX switch named "bpx_a.". The switch has two logical ports named '2.1' and '2.2' and a physical port named '3.1'which does not contain any logical ports. Finally it assumes that an ATM service object profile named 'so_gold' exists. The program creates an ATM PVC between the two logical ports and creates a logical port on the physical port.

import org.omg.CORBA.StringHolder;
 
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
 
import com.syndesis.SYcrbAV.SessionFactory;
import com.syndesis.SYcrbAV.SessionFactoryHelper;
import com.syndesis.SYcrbAV.Session;
import com.syndesis.SYcrbAV.SessionHelper;
import com.syndesis.SYcrbAV.ServiceObjectManager;
import com.syndesis.SYcrbAV.ServiceObjectManagerHelper;
import com.syndesis.SYcrbAV.TransactionManager;
import com.syndesis.SYcrbAV.TransactionManagerHelper;
import com.syndesis.SYcrbAV.TransactionMode;
import com.syndesis.SYcrbAV.AVException;
import com.syndesis.SYcrbAV.AttributeValueItemSeqSeqHolder;
 
import com.syndesis.SYcrbNPT.NetworkElementFactory;
import com.syndesis.SYcrbNPT.NetworkElementFactoryHelper;
import com.syndesis.SYcrbNPT.NetworkElement;
 
import com.syndesis.SYcrbNPT.Lister;
import com.syndesis.SYcrbNPT.SearchItem;
import com.syndesis.SYcrbNPT.OrderByItem;
import com.syndesis.SYcrbNPT.Operation;
 
import com.syndesis.SYcrbNPT.AttributeValueItem;
import com.syndesis.SYcrbNPT.AttributeValueItemSeqHolder;
import com.syndesis.SYcrbNPT.AttributeItemSeqHolder;
import com.syndesis.SYcrbNPT.AttributeErrorItem;
import com.syndesis.SYcrbNPT.AttributeErrorItemSeqHolder;
import com.syndesis.SYcrbNPT.AttributeResultItemSeqSeqHolder;
 
import com.syndesis.SYcrbNPT.NptException;
import com.syndesis.SYcrbNPT.SY_OBJECTID_COLUMN;
 
 
public class sample {
 
  static final String nptRootContextName = "nptSessionRoot";
  static final String hostName           = "opal";
  static final String userName           = "superUser";
  static final String sessionFactoryName = "AVSessionFactory";
  static final String trManagerName      = "transactionManager";
  static final String soManagerName      = "com.syndesis.frrm.RAsvServiceObject";
  static final String neFactoryName      = "networkElementFactory";
 
  public static void main (String argv[]) {
 
    SessionFactory sessionFactory;
    Session session;
    NamingContext sessionServicesContext;
    ServiceObjectManager soManager;
    TransactionManager trManager;
    NetworkElementFactory neFactory;
 
    org.omg.CORBA.Object tempObj;
    NameComponent[] name;
 
    try {
     System.out.println("initialize ORB");
     org.omg.CORBA.ORB orb = IE.Iona.OrbixWeb.CORBA.ORB.init();
 
     System.out.println("get root naming service context");
     tempObj = orb.resolve_initial_references("NameService");
     NamingContext rootContext = NamingContextHelper.narrow(tempObj);
 
     System.out.println("get Activator session factory object");
     name = new NameComponent[3];
     name[0] = new NameComponent(nptRootContextName, "");
     name[1] = new NameComponent(hostName, "");
     name[2] = new NameComponent(sessionFactoryName, "");
     tempObj = rootContext.resolve(name);
      sessionFactory = SessionFactoryHelper.narrow(tempObj);
 
      System.out.println("create a new session");
      session = SessionHelper.narrow(sessionFactory.createMaster(userName, ""));
 
      System.out.println("get session services naming context");
      sessionServicesContext = session.getServices();
 
      System.out.println("get ATM Service Object Manager");
      name = new NameComponent[1];
      name[0] = new NameComponent(soManagerName, "");
      tempObj = sessionServicesContext.resolve(name);
      soManager = ServiceObjectManagerHelper.narrow(tempObj);
 
      TransactionMode trMode = TransactionMode.Atomic;
      StringHolder trId = new StringHolder();
      trId.value = "";
      AttributeValueItem[] trAttrs = new AttributeValueItem[1];
      trAttrs[0] = new AttributeValueItem("briefdescription", "create SO");
 
      AttributeValueItemSeqHolder soAttrs = new AttributeValueItemSeqHolder();
      soAttrs.value    = new AttributeValueItem[4];
      soAttrs.value[0] = new AttributeValueItem("a_tp","bpx_a./2.1");
      soAttrs.value[1] = new AttributeValueItem("z_tp","bpx_a./2.2");
      soAttrs.value[2] = new AttributeValueItem("name", "sample SO");
      soAttrs.value[3] = new AttributeValueItem("profilename",      "so_gold");
 
      System.out.println("create ATM Service Object");
      String soid = soManager.create(trMode, trId, trAttrs, soAttrs);
      System.out.println("soid="+soid);
 
      trMode = TransactionMode.Current;
      trId.value = "";
      AttributeValueItemSeqSeqHolder dHolder = new AttributeValueItemSeqSeqHolder();
 
      System.out.println("get SO details");
      soManager.getDetails(soid, trMode, trId, dHolder);
      AttributeValueItem[][] details = dHolder.value;
 
      for (int i=0; i<details.length; i++) {
       for (int j=0; j<details[i].length; j++) {
         System.out.print(details[i][j].name+"="+details[i][j].value+" ");
        }
        System.out.println();
      }
 
      System.out.println("get Network Element Factory");
      name = new NameComponent[1];
      name[0] = new NameComponent(neFactoryName, "");
      tempObj = sessionServicesContext.resolve(name);
      neFactory = NetworkElementFactoryHelper.narrow(tempObj);
 
      NetworkElement pport = findPPort(neFactory, "Network1", "bpx_a.", "3", "1");
      System.out.println("pport oid = "+pport.getPersistentId());
 
      System.out.println("get Transaction Manager");
      name = new NameComponent[1];
      name[0] = new NameComponent(trManagerName, "");
      tempObj = sessionServicesContext.resolve(name);
      trManager = TransactionManagerHelper.narrow(tempObj);
 
      String troid = null;
      try {
        AttributeValueItem[] trAttrs2 = new AttributeValueItem[1];
        trAttrs2[0] = new AttributeValueItem("briefdescription", "create LPort");
        System.out.println("start transaction");
        troid = trManager.start(trAttrs2);
 
        System.out.println("create lport");
        String lportClassName = "CSalAtmLport";
        NetworkElement lport = neFactory.createNetworkElement(lportClassName);
 
        AttributeValueItem[] lportAttrs = new AttributeValueItem[3];
        lportAttrs[0] = new AttributeValueItem("srname", "syndesis1");
        lportAttrs[1] = new AttributeValueItem("srnode", pport.getValue("srnode"));
        lportAttrs[2] = new AttributeValueItem("srport", pport.getPersistentId());
 
        lport.overwriteAttributes(lportAttrs);
        AttributeErrorItemSeqHolder errHolder = new AttributeErrorItemSeqHolder();
        errHolder.value = new AttributeErrorItem[0];
        lport.save(errHolder);
        System.out.println("lport oid = "+lport.getPersistentId());
 
        System.out.println("apply transaction");
        trManager.apply(troid);
      } catch (Exception e) {
        System.out.println("lport creation unsuccessful: "+e);
        if (troid != null) {
          try {
            System.out.println("abandon transaction");
            trManager.abandon(troid);
          } catch (Exception f) {
         }
       }
     }
 
      System.out.println("end the session");
      session.remove();
 
      System.out.println("done");
 
      } catch (Exception e) {
      System.err.println("Unexpected exception: "+e);
    }
  }
 
  static NetworkElement findPPort(NetworkElementFactory neFactory,
                  String network, String node, String slot, String port)
    throws NptException {
    
      SearchItem[]  searchList   = new SearchItem[4];
      searchList[0] = new SearchItem("srnode.srnetwork.srname", Operation.EqualTo, network);
      searchList[1] = new SearchItem("srnode.srname",           Operation.EqualTo, node);
      searchList[2] = new SearchItem("srslotnumber",            Operation.EqualTo, slot);
      searchList[3] = new SearchItem("srportnumber",            Operation.EqualTo, port);
      String[]      columnList   = new String[1];
      columnList[0]              = SY_OBJECTID_COLUMN.value;  // "sy_objectid";
      OrderByItem[] orderByList  = new OrderByItem[0];
      String[]      uniqueByList = new String[0];
      Lister lister = neFactory.createLister("SRppPhysicalPort");
      try {
        lister.getList(searchList, columnList, orderByList, uniqueByList);
        if (lister.getCount() == 1) {
          AttributeItemSeqHolder columnListHolder = new AttributeItemSeqHolder();
          AttributeResultItemSeqSeqHolder rh = new AttributeResultItemSeqSeqHolder();
          lister.getItems(1, 1, columnListHolder, rh);
          return neFactory.bindNetworkElement(rh.value[0][0]);
       } else
         return null;
      } finally {
          try {
          lister.remove();
       } catch (Exception e) {
         }
      }
  }
 
}

nrsample.java

This example exercises the CORBA interface to NNI Resiliency. The resiliency operation to be performed and the object id of the link must be specified on the command line.

import org.omg.CORBA.StringHolder;
 
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
 
import com.syndesis.SYcrbAV.SessionFactory;
import com.syndesis.SYcrbAV.SessionFactoryHelper;
import com.syndesis.SYcrbAV.Session;
import com.syndesis.SYcrbAV.SessionHelper;
import com.syndesis.SYcrbAV.NNIResiliencyManager;
import com.syndesis.SYcrbAV.NNIResiliencyManagerHelper;
 
 
public class nrsample {
 
  static final String nptRootContextName = "nptSessionRoot";
  static final String hostName           = "opal";
  static final String userName           = "superUser";
  static final String sessionFactoryName = "AVSessionFactory";
  static final String nrManagerName      = "com.syndesis.resiliency.NNIResiliency";
 
  public static void main(String args[]) {
 
    SessionFactory sessionFactory;
    Session session;
    NamingContext sessionServicesContext;
    NNIResiliencyManager nrManager;
 
    org.omg.CORBA.Object tempObj;
    NameComponent[] name;
 
   if (args.length != 2) {
      System.out.println("Usage: java nrsample {linkfail|linkrecover|linkrebalance} linkoid");
      System.exit(1);
    }
 
    String cmd = args[0];
    String linkoid = args[1];
 
    try {
      System.out.println("initialize ORB");
      org.omg.CORBA.ORB orb = IE.Iona.OrbixWeb.CORBA.ORB.init();
 
      System.out.println("get root naming service context");
      tempObj = orb.resolve_initial_references("NameService");
      NamingContext rootContext = NamingContextHelper.narrow(tempObj);
 
      System.out.println("get Activator session factory object");
      name = new NameComponent[3];
      name[0] = new NameComponent(nptRootContextName, "");
      name[1] = new NameComponent(hostName, "");
      name[2] = new NameComponent(sessionFactoryName, "");
      tempObj = rootContext.resolve(name);
      sessionFactory = SessionFactoryHelper.narrow(tempObj);
 
      System.out.println("create a new session");
      session = SessionHelper.narrow(sessionFactory.createMaster(userName, ""));
 
      System.out.println("get session services naming context");
      sessionServicesContext = session.getServices();
 
      System.out.println("get NNI Resiliency Manager");
      name = new NameComponent[1];
      name[0] = new NameComponent(nrManagerName, "");
      tempObj = sessionServicesContext.resolve(name);
      nrManager = NNIResiliencyManagerHelper.narrow(tempObj);
 
      if (cmd.equalsIgnoreCase("linkfail")) {
        System.out.println("linkFail "+linkoid);
        nrManager.linkFail(linkoid);
      } else if (cmd.equalsIgnoreCase("linkrecover")) {
        System.out.println("linkRecover "+linkoid);
        nrManager.linkRecover(linkoid);
     } else if (cmd.equalsIgnoreCase("linkrebalance")) {
       System.out.println("linkRebalance "+linkoid);
        nrManager.linkRebalance(linkoid);
     } else {
        System.out.println("'"+cmd+"' is not a valid NNI resiliency command");
      }
 
      System.out.println("end the session");
      session.remove();
 
      System.out.println("done");
 
    } catch (Exception e) {
      System.err.println("Unexpected exception: "+e);
   }
  }

evsample.java

This example configures itself to receive all events related to CPC transactions and upload requests generated in other sessions. When an event is received, it is printed to standard output. The maximum number of events to be received before terminating the session must be specified on the command line. The example should be run in parallel with the 'sample.java' example in order to receive any events.

import org.omg.CORBA.StringHolder;
import org.omg.CORBA.IntHolder;
import org.omg.CORBA.Any;
 
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
 
import org.omg.CORBA.OrbixEventsAdmin.ChannelManager;
import org.omg.CORBA.OrbixEventsAdmin.ChannelManagerHelper;
import org.omg.CORBA.CosEventChannelAdmin.EventChannel;
import org.omg.CORBA.CosEventChannelAdmin.ProxyPushSupplier;
import org.omg.CORBA.CosEventComm._PushConsumerImplBase;
 
import com.syndesis.SYcrbAV.SessionFactory;
import com.syndesis.SYcrbAV.SessionFactoryHelper;
import com.syndesis.SYcrbAV.Session;
import com.syndesis.SYcrbAV.SessionHelper;
 
import com.syndesis.SYcrbNPT.EventSourceFactory;
import com.syndesis.SYcrbNPT.EventSourceFactoryHelper;
import com.syndesis.SYcrbNPT.EventSource;
import com.syndesis.SYcrbNPT.EventSourcePackage.FilterMode;
import com.syndesis.SYcrbNPT.MVCEvent;
import com.syndesis.SYcrbNPT.MVCEventHelper;
 
 
public class evsample {
 
  static final String nptRootContextName = "nptSessionRoot";
  static final String hostName            = "opal";
  static final String userName            = "superUser";
  static final String sessionFactoryName = "AVSessionFactory";
  static final String esFactoryName      = "eventSourceFactory";
  static final String eventChannelName   = "myActivatorEvents";
 
  public static void main(String args[]) {
 
    SessionFactory sessionFactory;
    Session session;
    NamingContext sessionServicesContext;
    EventSourceFactory esFactory;
    EventSource eventSource;
 
    ChannelManager eventChannelManager;
    EventChannel eventChannel;
 
    org.omg.CORBA.Object tempObj;
    NameComponent[] name;
 
    if (args.length != 1) {
      System.out.println("Usage: java evsample {maxEvents}");
      System.exit(1);
    }
 
    int maxEvents = Integer.parseInt(args[0]);
 
    try {
      System.out.println("initialize ORB");
      org.omg.CORBA.ORB orb = IE.Iona.OrbixWeb.CORBA.ORB.init();
 
      System.out.println("get Orbix Event Services channel manager");
      eventChannelManager = ChannelManagerHelper.bind("ChannelManager:ES", hostName);
 
      System.out.println("create event channel");
      eventChannel = eventChannelManager.create(eventChannelName, false);
 
      System.out.println("get root naming service context");
      tempObj = orb.resolve_initial_references("NameService");
      NamingContext rootContext = NamingContextHelper.narrow(tempObj);
 
      System.out.println("get Activator session factory object");
      name = new NameComponent[3];
      name[0] = new NameComponent(nptRootContextName, "");
      name[1] = new NameComponent(hostName, "");
      name[2] = new NameComponent(sessionFactoryName, "");
      tempObj = rootContext.resolve(name);
      sessionFactory = SessionFactoryHelper.narrow(tempObj);
 
      System.out.println("create a new session");
      session = SessionHelper.narrow(sessionFactory.createMaster(userName, ""));
 
      System.out.println("get session services naming context");
      sessionServicesContext = session.getServices();
 
      System.out.println("get event source factory");
      name = new NameComponent[1];
      name[0] = new NameComponent(esFactoryName, "");
      tempObj = sessionServicesContext.resolve(name);
      esFactory = EventSourceFactoryHelper.narrow(tempObj);
 
      System.out.println("create event source");
      IntHolder esId = new IntHolder();
      eventSource = esFactory.createEventSource(eventChannel, esId);
 
      System.out.println("create push consumer");
      PushConsumerImpl myPushConsumer = new PushConsumerImpl();
 
      System.out.println("connect push consumer to event channel");
      ProxyPushSupplier pps = eventChannel.for_consumers().obtain_push_supplier();
      pps.connect_push_consumer(myPushConsumer);
 
      System.out.println("enable transaction, upload, and CS EM events");
      String[] modelId = { "SYcadChangeOrder:0", "SYuplUploadRequest:0",
               "CSntNetwork:0", "CSndNode:0",
               "CSalAtmLport:0", "CSapAtmPport:0", "CSacAtmVc:0" };
      eventSource.enableEvent("*", "*", modelId, FilterMode.intraSession);
 
      System.out.println("wait for events");
      while (myPushConsumer.eventCount < maxEvents) {
        IE.Iona.OrbixWeb._CORBA.Orbix.processNextEvent();
      }
 
      System.out.println("disconnect push consumer from event channel");
      pps.disconnect_push_supplier();
 
      System.out.println("destroy event source");
      esFactory.destroyEventSource(eventSource.getEventSourceId());
 
      System.out.println("destroy event channel");
      eventChannelManager.destroy(eventChannelName, false);
 
      System.out.println("end the session");
      session.remove();
 
      System.out.println("done");
 
    } catch (Exception e) {
      System.err.println("Unexpected exception: "+e);
    }
 
    System.exit(0);
  }
}
 
class PushConsumerImpl extends _PushConsumerImplBase {
 
  public int eventCount = 0;
 
  public PushConsumerImpl() {}
 
  public void push(Any theAny) {
 
    try {
     if (theAny.type().equal(MVCEventHelper.type())) {
        MVCEvent event = MVCEventHelper.extract(theAny);
 
        System.out.print("Event "+eventCount+": class="+event.eventClass);
        System.out.print(" type="+event.eventType+" model=[ ");
        for (int i=0; i<event.modelIds.length; i++)
          System.out.print(event.modelIds[i]+" ");
        System.out.println("] parameters="+event.parameters);
      } 
    } catch (Exception e) {
      System.err.println("Unexpected exception in push consumer: "+e);
    }
    eventCount++;
  }
 
  public void disconnect_push_consumer() {}
}
 


hometocprevnextglossaryfeedbacksearchhelp
Posted: Thu Aug 3 16:20:12 PDT 2000
Copyright 1989-2000©Cisco Systems Inc.