private void addEvent(EventReg 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=new Long(reg.eventID);
  eventByID.put(id,reg);
  eventByTime.put(reg,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 ) { 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 = new Long ( reg . eventID ) ; eventByID . put ( id , reg ) ; eventByTime . put ( reg , 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 single event registration for a given service id , we avoid creating a singleton array in that case .
