1 10 11 package com.sun.jmx.snmp.agent; 12 13 14 15 import java.io.Serializable ; 18 import java.util.Date ; 19 import java.util.Vector ; 20 import java.util.Enumeration ; 21 import java.util.List ; 22 import java.util.ArrayList ; 23 24 import javax.management.Notification ; 27 import javax.management.ObjectName ; 28 import javax.management.NotificationFilter ; 29 import javax.management.NotificationListener ; 30 import javax.management.NotificationBroadcaster ; 31 import javax.management.MBeanNotificationInfo ; 32 import javax.management.ListenerNotFoundException ; 33 import com.sun.jmx.snmp.SnmpOid; 34 import com.sun.jmx.snmp.SnmpValue; 35 import com.sun.jmx.snmp.SnmpVarBind; 36 import com.sun.jmx.snmp.SnmpStatusException; 37 38 68 public abstract class SnmpTableSupport implements SnmpTableEntryFactory, 69 SnmpTableCallbackHandler, Serializable { 72 74 80 83 protected List entries; 84 85 88 protected SnmpMibTable meta; 89 90 93 protected SnmpMib theMib; 94 95 101 105 private boolean registrationRequired = false; 106 107 108 109 115 128 protected SnmpTableSupport(SnmpMib mib) { 129 theMib = mib; 130 meta = getRegisteredTableMeta(mib); 131 bindWithTableMeta(); 132 entries = allocateTable(); 133 } 134 135 136 142 153 public abstract void createNewEntry(SnmpMibSubRequest request, 154 SnmpOid rowOid, int depth, 155 SnmpMibTable meta) 156 throws SnmpStatusException; 157 158 159 165 171 public Object getEntry(int pos) { 173 if (entries == null) return null; 174 return entries.get(pos); 175 } 176 177 182 public int getSize() { 183 return meta.getSize(); 184 } 185 186 209 public void setCreationEnabled(boolean remoteCreationFlag) { 210 meta.setCreationEnabled(remoteCreationFlag); 211 } 212 213 224 public boolean isCreationEnabled() { 225 return meta.isCreationEnabled(); 226 } 227 228 236 public boolean isRegistrationRequired() { 237 return registrationRequired; 238 } 239 240 252 public SnmpIndex buildSnmpIndex(SnmpOid rowOid) 253 throws SnmpStatusException { 254 return buildSnmpIndex(rowOid.longValue(false), 0); 255 } 256 257 268 public abstract SnmpOid buildOidFromIndex(SnmpIndex index) 269 throws SnmpStatusException; 270 271 288 public abstract ObjectName buildNameFromIndex(SnmpIndex index) 289 throws SnmpStatusException; 290 291 292 298 314 public void addEntryCb(int pos, SnmpOid row, ObjectName name, 315 Object entry, SnmpMibTable meta) 316 throws SnmpStatusException { 317 try { 318 if (entries != null) entries.add(pos,entry); 319 } catch (Exception e) { 320 throw new SnmpStatusException(SnmpStatusException.noSuchName); 321 } 322 } 323 324 340 public void removeEntryCb(int pos, SnmpOid row, ObjectName name, 341 Object entry, SnmpMibTable meta) 342 throws SnmpStatusException { 343 try { 344 if (entries != null) entries.remove(pos); 345 } catch (Exception e) { 346 } 347 } 348 349 350 351 366 public void 367 addNotificationListener(NotificationListener listener, 368 NotificationFilter filter, Object handback) { 369 meta.addNotificationListener(listener,filter,handback); 370 } 371 372 384 public synchronized void 385 removeNotificationListener(NotificationListener listener) 386 throws ListenerNotFoundException { 387 meta.removeNotificationListener(listener); 388 } 389 390 395 public MBeanNotificationInfo [] getNotificationInfo() { 396 return meta.getNotificationInfo(); 397 } 398 399 405 418 protected abstract SnmpIndex buildSnmpIndex(long oid[], int start ) 419 throws SnmpStatusException; 420 421 433 protected abstract SnmpMibTable getRegisteredTableMeta(SnmpMib mib); 434 435 436 442 453 protected List allocateTable() { 454 return new ArrayList (); 455 } 456 457 477 protected void addEntry(SnmpIndex index, Object entry) 478 throws SnmpStatusException { 479 SnmpOid oid = buildOidFromIndex(index); 480 ObjectName name = null; 481 if (isRegistrationRequired()) { 482 name = buildNameFromIndex(index); 483 } 484 meta.addEntry(oid,name,entry); 485 } 486 487 500 protected void addEntry(SnmpIndex index, ObjectName name, Object entry) 501 throws SnmpStatusException { 502 SnmpOid oid = buildOidFromIndex(index); 503 meta.addEntry(oid,name,entry); 504 } 505 506 522 protected void removeEntry(SnmpIndex index, Object entry) 523 throws SnmpStatusException { 524 SnmpOid oid = buildOidFromIndex(index); 525 meta.removeEntry(oid,entry); 526 } 527 528 533 539 protected Object [] getBasicEntries() { 540 if (entries == null) return null; 541 Object [] array= new Object [entries.size()]; 542 entries.toArray(array); 543 return array; 544 } 545 546 550 protected void bindWithTableMeta() { 551 if (meta == null) return; 552 registrationRequired = meta.isRegistrationRequired(); 553 meta.registerEntryFactory(this); 554 } 555 556 } 557 | Popular Tags |