jdk/src/share/classes/sun/management/snmp/util/SnmpNamedListTableCache.java
changeset 11530 a9d059c15b80
parent 5506 202f599c92aa
child 14342 8435a30053c1
equal deleted inserted replaced
11529:e08d565262ce 11530:a9d059c15b80
    53 
    53 
    54     /**
    54     /**
    55      * This map associate an entry name with the SnmpOid index that's
    55      * This map associate an entry name with the SnmpOid index that's
    56      * been allocated for it.
    56      * been allocated for it.
    57      **/
    57      **/
    58     protected TreeMap names = new TreeMap();
    58     protected TreeMap<String, SnmpOid> names = new TreeMap<>();
    59 
    59 
    60     /**
    60     /**
    61      * The last allocate index.
    61      * The last allocate index.
    62      **/
    62      **/
    63     protected long last = 0;
    63     protected long last = 0;
    78      *        {@link #updateCachedDatas(Object,List)}.
    78      *        {@link #updateCachedDatas(Object,List)}.
    79      * @param rank Rank of the given <var>item</var> in the
    79      * @param rank Rank of the given <var>item</var> in the
    80      *        <var>rawDatas</var> list iterator.
    80      *        <var>rawDatas</var> list iterator.
    81      * @param item The raw data object for which a key name must be determined.
    81      * @param item The raw data object for which a key name must be determined.
    82      **/
    82      **/
    83     protected abstract String getKey(Object context, List rawDatas,
    83     protected abstract String getKey(Object context, List<?> rawDatas,
    84                                      int rank, Object item);
    84                                      int rank, Object item);
    85 
    85 
    86     /**
    86     /**
    87      * Find a new index for the entry corresponding to the
    87      * Find a new index for the entry corresponding to the
    88      * given <var>item</var>.
    88      * given <var>item</var>.
    95      *        {@link #updateCachedDatas(Object,List)}.
    95      *        {@link #updateCachedDatas(Object,List)}.
    96      * @param rank Rank of the given <var>item</var> in the
    96      * @param rank Rank of the given <var>item</var> in the
    97      *        <var>rawDatas</var> list iterator.
    97      *        <var>rawDatas</var> list iterator.
    98      * @param item The raw data object for which an index must be determined.
    98      * @param item The raw data object for which an index must be determined.
    99      **/
    99      **/
   100     protected SnmpOid makeIndex(Object context, List rawDatas,
   100     protected SnmpOid makeIndex(Object context, List<?> rawDatas,
   101                                 int rank, Object item) {
   101                                 int rank, Object item) {
   102 
   102 
   103         // check we are in the limits of an unsigned32.
   103         // check we are in the limits of an unsigned32.
   104         if (++last > 0x00000000FFFFFFFFL) {
   104         if (++last > 0x00000000FFFFFFFFL) {
   105             // we just wrapped.
   105             // we just wrapped.
   149      *        {@link #updateCachedDatas(Object,List)}.
   149      *        {@link #updateCachedDatas(Object,List)}.
   150      * @param rank Rank of the given <var>item</var> in the
   150      * @param rank Rank of the given <var>item</var> in the
   151      *        <var>rawDatas</var> list iterator.
   151      *        <var>rawDatas</var> list iterator.
   152      * @param item The raw data object for which an index must be determined.
   152      * @param item The raw data object for which an index must be determined.
   153      **/
   153      **/
   154     protected SnmpOid getIndex(Object context, List rawDatas,
   154     protected SnmpOid getIndex(Object context, List<?> rawDatas,
   155                                int rank, Object item) {
   155                                int rank, Object item) {
   156         final String key   = getKey(context,rawDatas,rank,item);
   156         final String key   = getKey(context,rawDatas,rank,item);
   157         final Object index = (names==null||key==null)?null:names.get(key);
   157         final Object index = (names==null||key==null)?null:names.get(key);
   158         final SnmpOid result =
   158         final SnmpOid result =
   159             ((index != null)?((SnmpOid)index):makeIndex(context,rawDatas,
   159             ((index != null)?((SnmpOid)index):makeIndex(context,rawDatas,
   172      * finally replace the {@link #names} TreeMap by the new allocated
   172      * finally replace the {@link #names} TreeMap by the new allocated
   173      * TreeMap.
   173      * TreeMap.
   174      * @param rawDatas The table datas from which the cached data will be
   174      * @param rawDatas The table datas from which the cached data will be
   175      *        computed.
   175      *        computed.
   176      **/
   176      **/
   177     protected SnmpCachedData updateCachedDatas(Object context, List rawDatas) {
   177     protected SnmpCachedData updateCachedDatas(Object context, List<?> rawDatas) {
   178         TreeMap ctxt = new TreeMap();
   178         TreeMap<String,SnmpOid> ctxt = new TreeMap<>();
   179         final SnmpCachedData result =
   179         final SnmpCachedData result =
   180             super.updateCachedDatas(context,rawDatas);
   180             super.updateCachedDatas(context,rawDatas);
   181         names = ctxt;
   181         names = ctxt;
   182         return result;
   182         return result;
   183     }
   183     }
   189      * contextual cache.
   189      * contextual cache.
   190      * @param userData The request contextual cache allocated by
   190      * @param userData The request contextual cache allocated by
   191      *        the {@link JvmContextFactory}.
   191      *        the {@link JvmContextFactory}.
   192      *
   192      *
   193      **/
   193      **/
   194     protected abstract List   loadRawDatas(Map userData);
   194     protected abstract List<?>  loadRawDatas(Map<Object,Object> userData);
   195 
   195 
   196     /**
   196     /**
   197      *The name under which the raw data is to be found/put in
   197      *The name under which the raw data is to be found/put in
   198      *        the request contextual cache.
   198      *        the request contextual cache.
   199      **/
   199      **/
   210      *        the {@link JvmContextFactory}.
   210      *        the {@link JvmContextFactory}.
   211      * @param key The name under which the raw data is to be found/put in
   211      * @param key The name under which the raw data is to be found/put in
   212      *        the request contextual cache.
   212      *        the request contextual cache.
   213      *
   213      *
   214      **/
   214      **/
   215     protected List getRawDatas(Map<Object, Object> userData, String key) {
   215     protected List<?> getRawDatas(Map<Object, Object> userData, String key) {
   216         List rawDatas = null;
   216         List<?> rawDatas = null;
   217 
   217 
   218         // Look for memory manager list in request contextual cache.
   218         // Look for memory manager list in request contextual cache.
   219         if (userData != null)
   219         if (userData != null)
   220             rawDatas = (List) userData.get(key);
   220             rawDatas =  (List<?>)userData.get(key);
   221 
   221 
   222         if (rawDatas == null) {
   222         if (rawDatas == null) {
   223             // No list in contextual cache, get it from API
   223             // No list in contextual cache, get it from API
   224             rawDatas =  loadRawDatas(userData);
   224             rawDatas = loadRawDatas(userData);
   225 
   225 
   226 
   226 
   227             // Put list in cache...
   227             // Put list in cache...
   228             if (rawDatas != null && userData != null)
   228             if (rawDatas != null && userData != null)
   229                 userData.put(key, rawDatas);
   229                 userData.put(key, rawDatas);
   248 
   248 
   249         final Map<Object, Object> userData =
   249         final Map<Object, Object> userData =
   250             (context instanceof Map)?Util.<Map<Object, Object>>cast(context):null;
   250             (context instanceof Map)?Util.<Map<Object, Object>>cast(context):null;
   251 
   251 
   252         // Look for memory manager list in request contextual cache.
   252         // Look for memory manager list in request contextual cache.
   253         final List rawDatas = getRawDatas(userData,getRawDatasKey());
   253         final List<?> rawDatas = getRawDatas(userData,getRawDatasKey());
   254 
   254 
   255         log.debug("updateCachedDatas","rawDatas.size()=" +
   255         log.debug("updateCachedDatas","rawDatas.size()=" +
   256               ((rawDatas==null)?"<no data>":""+rawDatas.size()));
   256               ((rawDatas==null)?"<no data>":""+rawDatas.size()));
   257 
   257 
   258         TreeMap ctxt = new TreeMap();
   258         TreeMap<String,SnmpOid> ctxt = new TreeMap<>();
   259         final SnmpCachedData result =
   259         final SnmpCachedData result =
   260             super.updateCachedDatas(ctxt,rawDatas);
   260             super.updateCachedDatas(ctxt,rawDatas);
   261         names = ctxt;
   261         names = ctxt;
   262         return result;
   262         return result;
   263     }
   263     }