private void addEvent(EventReg reg){
synchronized (reg) {
    if (reg.listener == null)     return;
    EntryRep[] tmpls=reg.tmpl.attributeSetTemplates;
    if (tmpls != null) {
      for (int i=tmpls.length; --i >= 0; ) {
        EntryClass eclass=tmpls[i].eclass;
        eclass.setNumTemplates(eclass.getNumTemplates() + 1);
      }
    }
    Long id=reg.eventID;
    eventByID.put(id,reg);
    EventRegKeyExpiration regExpirationKey=new EventRegKeyExpiration(reg,reg.leaseExpiration);
    if (loggerEventExpire.isLoggable(Level.FINE)) {
      loggerEventExpire.fine("[" + System.identityHashCode(regExpirationKey) + "]: Event ["+ regExpirationKey.reg.eventID+ "]: Registered with lease ["+ regExpirationKey.leaseExpiration+ "] and listener ["+ reg.listener);
    }
    eventByTime.put(regExpirationKey,reg);
    if (reg.tmpl.serviceID != null) {
      Object val=subEventByService.get(reg.tmpl.serviceID);
      if (val == null)       val=reg;
 else       if (val instanceof EventReg)       val=new EventReg[]{(EventReg)val,reg};
 else       val=arrayAdd((EventReg[])val,reg);
      subEventByService.put(reg.tmpl.serviceID,val);
    }
 else {
      subEventByID.put(id,reg);
    }
    computeMaxLeases();
  }
}

private void addEvent ( EventReg reg ) { synchronized ( reg ) { if ( reg . listener == null ) return ; EntryRep [ ] tmpls = reg . tmpl . attributeSetTemplates ; if ( tmpls != null ) { for ( int i = tmpls . length ; -- i >= 0 ; ) { EntryClass eclass = tmpls [ i ] . eclass ; eclass . setNumTemplates ( eclass . getNumTemplates ( ) + 1 ) ; } } Long id = reg . eventID ; eventByID . put ( id , reg ) ; EventRegKeyExpiration regExpirationKey = new EventRegKeyExpiration ( reg , reg . leaseExpiration ) ; if ( loggerEventExpire . isLoggable ( Level . FINE ) ) { loggerEventExpire . fine ( "[" + System . identityHashCode ( regExpirationKey ) + "]: Event [" + regExpirationKey . reg . eventID + "]: Registered with lease [" + regExpirationKey . leaseExpiration + "] and listener [" + reg . listener ) ; } eventByTime . put ( regExpirationKey , reg ) ; if ( reg . tmpl . serviceID != null ) { Object val = subEventByService . get ( reg . tmpl . serviceID ) ; if ( val == null ) val = reg ; else if ( val instanceof EventReg ) val = new EventReg [ ] { ( EventReg ) val , reg } ; else val = arrayAdd ( ( EventReg [ ] ) val , reg ) ; subEventByService . put ( reg . tmpl . serviceID , val ) ; } else { subEventByID . put ( id , reg ) ; } computeMaxLeases ( ) ; } }
add an event registration to our state . this includes adding a template of each entryclass , putting the registration in the eventbyid map , in the eventbytime map , and in either subeventbyservice ( if the template is for a specific service id ) or subeventbyid . since we expect in most cases there will only ever be a s ` ingle event registration for a given service id , we avoid creating a singleton array in that case .
