/** * Return a table handler containing the Thread indexes. * Indexes are computed from the ThreadId. **/ protected SnmpCachedData updateCachedDatas(Object userData) { // We are getting all the input args final String[] args = JvmRuntimeImpl.getInputArguments(userData); // Time stamp for the cache final long time = System.currentTimeMillis(); SnmpOid indexes[] = new SnmpOid[args.length]; for(int i = 0; i < args.length; i++) { indexes[i] = new SnmpOid(i + 1); } return new SnmpCachedData(time, indexes, args); }
/** * Update cahed datas. * Obtains a {@link List} of raw datas by calling * {@link #getRawDatas(Map,String) getRawDatas((Map)context,getRawDatasKey())}.<br> * Then allocate a new {@link TreeMap} to serve as temporary map between * names and indexes, and call {@link #updateCachedDatas(Object,List)} * with that temporary map as context.<br> * Finally replaces the {@link #names} TreeMap by the temporary * TreeMap. * @param context The request contextual cache allocated by the * {@link JvmContextFactory}. **/ protected SnmpCachedData updateCachedDatas(Object context) { final Map<Object, Object> userData = (context instanceof Map)?Util.<Map<Object, Object>>cast(context):null; // Look for memory manager list in request contextual cache. final List<?> rawDatas = getRawDatas(userData,getRawDatasKey()); log.debug("updateCachedDatas","rawDatas.size()=" + ((rawDatas==null)?"<no data>":""+rawDatas.size())); TreeMap<String,SnmpOid> ctxt = new TreeMap<>(); final SnmpCachedData result = super.updateCachedDatas(ctxt,rawDatas); names = ctxt; return result; }
/** * Return a table handler containing the Thread indexes. * Indexes are computed from the ThreadId. **/ protected SnmpCachedData updateCachedDatas(Object userData) { // We are getting all the input args final String[] path = JvmRuntimeImpl.getLibraryPath(userData); // Time stamp for the cache final long time = System.currentTimeMillis(); final int len = path.length; SnmpOid indexes[] = new SnmpOid[len]; for(int i = 0; i < len; i++) { indexes[i] = new SnmpOid(i + 1); } return new SnmpCachedData(time, indexes, path); }
protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, SnmpTableHandler mmHandler, SnmpTableHandler mpHandler, Map<String, SnmpOid> poolIndexMap) { if (mmHandler instanceof SnmpCachedData) { updateTreeMap(table,userData,(SnmpCachedData)mmHandler, mpHandler,poolIndexMap); return; } SnmpOid mmIndex=null; while ((mmIndex = mmHandler.getNext(mmIndex))!=null) { final MemoryManagerMXBean mmm = (MemoryManagerMXBean)mmHandler.getData(mmIndex); if (mmm == null) continue; updateTreeMap(table,userData,mmm,mmIndex,poolIndexMap); } }
/** * Compares two indexes for equality. * * @param index The index to compare <CODE>this</CODE> with. * * @return <CODE>true</CODE> if the two indexes are equal, <CODE>false</CODE> otherwise. */ public boolean equals(SnmpIndex index) { if (size != index.getNbComponents()) return false; // The two vectors have the same length. // Compare each single element ... // SnmpOid oid1; SnmpOid oid2; Vector<SnmpOid> components= index.getComponents(); for(int i=0; i <size; i++) { oid1= oids.elementAt(i); oid2= components.elementAt(i); if (oid1.equals(oid2) == false) return false; } return true; }
void checkCurrentOid() throws SnmpStatusException { if(model != null) { SnmpOid oid = new SnmpOid(l.toArray()); if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "checkCurrentOid", "Checking access for : " + oid); } model.checkAccess(version, principal, securityLevel, pduType, securityModel, contextName, oid); } }
/** * Sends a trap using SNMP V1 trap format. * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination. * The community string used is the one located in the * <CODE>SnmpPeer</CODE> parameters * (<CODE>SnmpParameters.getRdCommunity() </CODE>). * * @param peer The <CODE>SnmpPeer</CODE> destination of the trap. * @param agentAddr The agent address to be used for the trap. * @param enterpOid The enterprise OID to be used for the trap. * @param generic The generic number of the trap. * @param specific The specific number of the trap. * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null. * @param time The time stamp (overwrite the current time). * * @exception IOException An I/O error occurred while sending the trap. * @exception SnmpStatusException If the trap exceeds the limit * defined by <CODE>bufferSize</CODE>. * * @since 1.5 */ @Override public void snmpV1Trap(SnmpPeer peer, SnmpIpAddress agentAddr, SnmpOid enterpOid, int generic, int specific, SnmpVarBindList varBindList, SnmpTimeticks time) throws IOException, SnmpStatusException { SnmpParameters p = (SnmpParameters) peer.getParams(); snmpV1Trap(peer.getDestAddr(), peer.getDestPort(), agentAddr, p.getRdCommunity(), enterpOid, generic, specific, varBindList, time); }
/** * Return a table handler containing the Thread indexes. * Indexes are computed from the ThreadId. **/ protected SnmpCachedData updateCachedDatas(Object userData) { // We are getting all the input args final String[] path = JvmRuntimeImpl.getClassPath(userData); // Time stamp for the cache final long time = System.currentTimeMillis(); final int len = path.length; SnmpOid indexes[] = new SnmpOid[len]; for(int i = 0; i < len; i++) { indexes[i] = new SnmpOid(i + 1); } return new SnmpCachedData(time, indexes, path); }
/** * Recompute cached data. * @param context A context object, valid during the duration of * of the call to this method, and that will be passed to * {@link #getIndex} and {@link #getData}. <br> * This method is intended to be called by * {@link #updateCachedDatas(Object)}. It is assumed that * the context is be allocated by before this method is called, * and released just after this method has returned.<br> * This class does not use the context object: it is a simple * hook for subclassed. * @param rawDatas The table datas from which the cached data will be * computed. * @return the computed cached data. **/ protected SnmpCachedData updateCachedDatas(Object context, List<?> rawDatas) { final int size = ((rawDatas == null)?0:rawDatas.size()); if (size == 0) return null; final long time = System.currentTimeMillis(); final Iterator<?> it = rawDatas.iterator(); final TreeMap<SnmpOid, Object> map = new TreeMap<>(SnmpCachedData.oidComparator); for (int rank=0; it.hasNext() ; rank++) { final Object item = it.next(); final SnmpOid index = getIndex(context, rawDatas, rank, item); final Object data = getData(context, rawDatas, rank, item); if (index == null) continue; map.put(index,data); } return new SnmpCachedData(time,map); }
public void createNewEntry(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { if (factory != null) factory.createNewEntry(req, rowOid, depth, this); else throw new SnmpStatusException( SnmpStatusException.snmpRspNoAccess); }
protected SnmpOid getNextOid(SnmpOid oid, Object userData) throws SnmpStatusException { final boolean dbg = log.isDebugOn(); if (dbg) log.debug("getNextOid", "previous=" + oid); // Get the data handler. // SnmpTableHandler handler = getHandler(userData); if (handler == null) { // This should never happen. // If we get here it's a bug. // if (dbg) log.debug("getNextOid", "handler is null!"); throw new SnmpStatusException(SnmpStatusException.noSuchInstance); } // Get the next oid // final SnmpOid next = handler.getNext(oid); if (dbg) log.debug("*** **** **** **** getNextOid", "next=" + next); // if next is null: we reached the end of the table. // if (next == null) throw new SnmpStatusException(SnmpStatusException.noSuchInstance); return next; }
public SnmpOid getEntryOid(int pos) { if (entryoids == null) return null; // if (pos == -1 || pos >= entryoids.size() ) return null; if (pos == -1 || pos >= entrycount ) return null; // return (SnmpOid) entryoids.get(pos); return entryoids[pos]; }
/** * Returns the arc of the next columnar object following "var". */ public long getNextVarEntryId( SnmpOid rowOid, long var, Object data ) throws SnmpStatusException { long nextvar = node.getNextVarId(var, data); while (!isReadableEntryId(rowOid, nextvar, data)) nextvar = node.getNextVarId(nextvar, data); return nextvar; }
public synchronized void addEntry(SnmpOid rowOid, ObjectName objname, Object entry) throws SnmpStatusException { if (! (entry instanceof JvmThreadInstanceEntryMBean) ) throw new ClassCastException("Entries for Table \"" + "JvmThreadInstanceTable" + "\" must implement the \"" + "JvmThreadInstanceEntryMBean" + "\" interface."); super.addEntry(rowOid, objname, entry); }
public synchronized void addEntry(SnmpOid rowOid, ObjectName objname, Object entry) throws SnmpStatusException { if (! (entry instanceof JvmRTClassPathEntryMBean) ) throw new ClassCastException("Entries for Table \"" + "JvmRTClassPathTable" + "\" must implement the \"" + "JvmRTClassPathEntryMBean" + "\" interface."); super.addEntry(rowOid, objname, entry); }
public boolean skipEntryVariable( SnmpOid rowOid, long var, Object data, int pduVersion) { try { JvmRTClassPathEntryMBean entry = (JvmRTClassPathEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); return node.skipVariable(var, data, pduVersion); } } catch (SnmpStatusException x) { return false; } }
protected boolean contains(SnmpOid oid, Object userData) { // Get the handler. // SnmpTableHandler handler = getHandler(userData); // handler should never be null. // if (handler == null) return false; return filter.contains(handler,oid); }
/** * Remove the specified entry from the table. * Also triggers the removeEntryCB() callback of the * {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} interface * if this node is bound to a factory. * * <p> * @param pos The position of the entry in the table. * * @param entry The entry to be removed. This parameter is not used * internally, it is simply passed along to the * removeEntryCB() callback. * * @exception SnmpStatusException if the specified entry couldn't * be removed. */ public synchronized void removeEntry(int pos, Object entry) throws SnmpStatusException { if (pos == -1) return; if (pos >= size) return; Object obj = entry; if (entries != null && entries.size() > pos) { obj = entries.elementAt(pos); entries.removeElementAt(pos); } ObjectName name = null; if (entrynames != null && entrynames.size() > pos) { name = entrynames.elementAt(pos); entrynames.removeElementAt(pos); } final SnmpOid rowOid = tableoids[pos]; removeOid(pos); size --; if (obj == null) obj = entry; if (factory != null) factory.removeEntryCb(pos,rowOid,name,obj,this); sendNotification(SnmpTableEntryNotification.SNMP_ENTRY_REMOVED, (new Date()).getTime(), obj, name); }
protected SnmpOid getNextOid(SnmpOid oid, Object userData) throws SnmpStatusException { final boolean dbg = log.isDebugOn(); try { if (dbg) log.debug("getNextOid", "previous=" + oid); // Get the data handler. // SnmpTableHandler handler = getHandler(userData); if (handler == null) { // This should never happen. // If we get here it's a bug. // if (dbg) log.debug("getNextOid", "handler is null!"); throw new SnmpStatusException(SnmpStatusException.noSuchInstance); } // Get the next oid // final SnmpOid next = handler.getNext(oid); if (dbg) log.debug("getNextOid", "next=" + next); // if next is null: we reached the end of the table. // if (next == null) throw new SnmpStatusException(SnmpStatusException.noSuchInstance); return next; } catch (SnmpStatusException x) { if (dbg) log.debug("getNextOid", "End of MIB View: " + x); throw x; } catch (RuntimeException r) { if (dbg) log.debug("getNextOid", "Unexpected exception: " + r); if (dbg) log.debug("getNextOid",r); throw r; } }
public boolean skipEntryVariable( SnmpOid rowOid, long var, Object data, int pduVersion) { try { JvmRTLibraryPathEntryMBean entry = (JvmRTLibraryPathEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); return node.skipVariable(var, data, pduVersion); } } catch (SnmpStatusException x) { return false; } }
/** * Search the position at which the given oid should be inserted * in the OID table (tableoids). * * <p> * @param oid The OID we would like to insert. * * @param fail Tells whether a SnmpStatusException must be generated * if the given OID is already present in the table. * * @return The position at which the OID should be inserted in * the table. When the OID is found, it returns the next * position. Note that it is not valid to insert twice the * same OID. This feature is only an optimization to improve * the getNextOid() behaviour. * * @exception SnmpStatusException if the OID is already present in the * table and <code>fail</code> is <code>true</code>. * **/ private int getInsertionPoint(SnmpOid oid, boolean fail) throws SnmpStatusException { final int failStatus = SnmpStatusException.snmpRspNotWritable; int low= 0; int max= size - 1; SnmpOid pos; int comp; int curr= low + (max-low)/2; while (low <= max) { // XX pos= (SnmpOid) oids.elementAt(curr); pos= tableoids[curr]; // never know ...we might find something ... // comp= oid.compareTo(pos); if (comp == 0) { if (fail) throw new SnmpStatusException(failStatus,curr); else return curr+1; } if (comp>0) { low= curr +1; } else { max= curr -1; } curr= low + (max-low)/2; } return curr; }
public void set(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { if (req.getSize() == 0) return; JvmRTInputArgsEntryMBean entry = (JvmRTInputArgsEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); node.set(req,depth); } }
public void check(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { if (req.getSize() == 0) return; JvmRTInputArgsEntryMBean entry = (JvmRTInputArgsEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); node.check(req,depth); } }
/** * WARNING: This should probably be moved to JvmMemPoolTableMetaImpl **/ private SnmpOid getJvmMemPoolEntryIndex(SnmpTableHandler handler, String poolName) { final int index = findInCache(handler,poolName); if (index < 0) return null; return ((SnmpCachedData)handler).indexes[index]; }
private static int findOid(SnmpOid[] oids, int count, SnmpOid oid) { final int size = count; int low= 0; int max= size - 1; int curr= low + (max-low)/2; //System.out.println("Try to retrieve: " + oid.toString()); while (low <= max) { final SnmpOid pos = oids[curr]; //System.out.println("Compare with" + pos.toString()); // never know ...we might find something ... // final int comp = oid.compareTo(pos); if (comp == 0) return curr; if (oid.equals(pos)) { return curr; } if (comp > 0) { low = curr + 1; } else { max = curr - 1; } curr = low + (max-low)/2; } return -1; }
SnmpMibSubRequestImpl(SnmpMibRequest global, Vector<SnmpVarBind> sublist, SnmpOid entryoid, boolean isnew, boolean getnextflag, SnmpVarBind rs) { this.global = global; varbinds = sublist; this.version = global.getVersion(); this.entryoid = entryoid; this.isnew = isnew; this.getnextflag = getnextflag; this.statusvb = rs; }
public void set(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { if (req.getSize() == 0) return; JvmRTBootClassPathEntryMBean entry = (JvmRTBootClassPathEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); node.set(req,depth); } }
public void check(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { if (req.getSize() == 0) return; JvmRTBootClassPathEntryMBean entry = (JvmRTBootClassPathEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); node.check(req,depth); } }
protected SnmpOid getNextOid(SnmpOid oid, Object userData) throws SnmpStatusException { log.debug("getNextOid", "previous=" + oid); // Get the data handler. // SnmpTableHandler handler = getHandler(userData); if (handler == null) { // This should never happen. // If we get here it's a bug. // log.debug("getNextOid", "handler is null!"); throw new SnmpStatusException(SnmpStatusException.noSuchInstance); } // Get the next oid // SnmpOid next = oid; while(true) { next = handler.getNext(next); if (next == null) break; if (getJvmThreadInstance(userData,next) != null) break; } log.debug("*** **** **** **** getNextOid", "next=" + next); // if next is null: we reached the end of the table. // if (next == null) throw new SnmpStatusException(SnmpStatusException.noSuchInstance); return next; }
public boolean skipEntryVariable( SnmpOid rowOid, long var, Object data, int pduVersion) { try { JvmRTBootClassPathEntryMBean entry = (JvmRTBootClassPathEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); return node.skipVariable(var, data, pduVersion); } } catch (SnmpStatusException x) { return false; } }
public void set(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { if (req.getSize() == 0) return; JvmMemPoolEntryMBean entry = (JvmMemPoolEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); node.set(req,depth); } }
protected boolean contains(SnmpOid oid, Object userData) { // Get the handler. // SnmpTableHandler handler = getHandler(userData); // handler should never be null. // if (handler == null) return false; return handler.contains(oid); }
public void check(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { if (req.getSize() == 0) return; JvmMemMgrPoolRelEntryMBean entry = (JvmMemMgrPoolRelEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); node.check(req,depth); } }
public void get(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { JvmRTBootClassPathEntryMBean entry = (JvmRTBootClassPathEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); node.get(req,depth); } }
public synchronized void addEntry(SnmpOid rowOid, ObjectName objname, Object entry) throws SnmpStatusException { if (! (entry instanceof JvmRTLibraryPathEntryMBean) ) throw new ClassCastException("Entries for Table \"" + "JvmRTLibraryPathTable" + "\" must implement the \"" + "JvmRTLibraryPathEntryMBean" + "\" interface."); super.addEntry(rowOid, objname, entry); }
public void get(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { JvmRTLibraryPathEntryMBean entry = (JvmRTLibraryPathEntryMBean) getEntry(rowOid); synchronized (this) { node.setInstance(entry); node.get(req,depth); } }