Examples of MemoryNotificationInfo


Examples of java.lang.management.MemoryNotificationInfo

        assertEquals("Lloyd", memoryNotifyInfo.getPoolName());
    }

    public void test_getUsage() {
        final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4);
        final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42);
        assertEquals(memoryUsage, memoryNotifyInfo.getUsage());
    }
View Full Code Here

Examples of java.lang.management.MemoryNotificationInfo

        assertEquals(memoryUsage, memoryNotifyInfo.getUsage());
    }

    public void test_get() {
        final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4);
        final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42);
        assertEquals(42, memoryNotifyInfo.getCount());
    }
View Full Code Here

Examples of java.lang.management.MemoryNotificationInfo

                SimpleType.LONG };

        CompositeType compositeType = getCompositeType(names, types);
        CompositeData data = new CompositeDataSupport(compositeType, names,
                values);
        MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
        assertEquals(values[0], info.getPoolName());
        assertEquals(values[2], info.getCount());
        assertNull(info.getUsage());
    }
View Full Code Here

Examples of java.lang.management.MemoryNotificationInfo

                SimpleType.LONG };

        CompositeType compositeType = getCompositeType(names, types);
        CompositeData data = new CompositeDataSupport(compositeType, names,
                values);
        MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
        assertEquals(values[0], info.getPoolName());
        assertEquals(values[2], info.getCount());
        MemoryUsage usage = info.getUsage();
        assertEquals(1, usage.getInit());
        assertEquals(2, usage.getUsed());
        assertEquals(3, usage.getCommitted());
        assertEquals(4, usage.getMax());
    }
View Full Code Here

Examples of java.lang.management.MemoryNotificationInfo

                SimpleType.LONG, SimpleType.LONG };

        CompositeType compositeType = getCompositeType(names, types);
        CompositeData data = new CompositeDataSupport(compositeType, names,
                values);
        MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
        assertEquals(values[0], info.getPoolName());
        assertEquals(values[2], info.getCount());
        MemoryUsage usage = info.getUsage();
        assertEquals(1, usage.getInit());
        assertEquals(2, usage.getUsed());
        assertEquals(3, usage.getCommitted());
        assertEquals(4, usage.getMax());
    }
View Full Code Here

Examples of java.lang.management.MemoryNotificationInfo

                SimpleType.LONG, SimpleType.STRING };

        CompositeType compositeType = getCompositeType(names, types);
        CompositeData data = new CompositeDataSupport(compositeType, names,
                values);
        MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
        assertEquals(values[0], info.getPoolName());
        assertEquals(values[2], info.getCount());
        MemoryUsage usage = info.getUsage();
        assertEquals(1, usage.getInit());
        assertEquals(2, usage.getUsed());
        assertEquals(3, usage.getCommitted());
        assertEquals(4, usage.getMax());
    }
View Full Code Here

Examples of java.lang.management.MemoryNotificationInfo

    }
   
    @Override
    public void handleNotification(Notification n, Object o) {
        CompositeData cd = (CompositeData) n.getUserData();
        MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
        // free the amount exceeded over the threshold and then a further half
        // so if threshold = heapmax/2, we will be trying to free
        // used - heapmax/2 + heapmax/4
        long toFree = 0L;
        if(n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
            long threshold = (long)(info.getUsage().getMax() * memoryThresholdFraction);
            toFree = info.getUsage().getUsed() - threshold + (long)(threshold * 0.5);

            //log
            String msg = "memory handler call- Usage threshold "
                + info.getUsage();
            if(!firstUsageThreshExceededLogged){
                log.info("first " + msg);
                firstUsageThreshExceededLogged = true;
            }else{
                log.debug(msg);
            }
        } else { // MEMORY_COLLECTION_THRESHOLD_EXCEEDED CASE
            long threshold = (long)(info.getUsage().getMax() * collectionMemoryThresholdFraction);
            toFree = info.getUsage().getUsed() - threshold + (long)(threshold * 0.5);
           
            //log
            String msg = "memory handler call - Collection threshold "
                + info.getUsage();
            if(!firstCollectionThreshExceededLogged){
                log.info("first " + msg);
                firstCollectionThreshExceededLogged = true;
            }else{
                log.debug(msg);
            }

        }
        clearSpillables();
        if (toFree < 0) {
            log.debug("low memory handler returning " +
                "because there is nothing to free");
            return;
        }
        synchronized(spillables) {
            Collections.sort(spillables, new Comparator<WeakReference<Spillable>>() {

                /**
                 * We don't lock anything, so this sort may not be stable if a WeakReference suddenly
                 * becomes null, but it will be close enough.
                 * Also between the time we sort and we use these spillables, they
                 * may actually change in size - so this is just best effort
                 */   
                @Override
                public int compare(WeakReference<Spillable> o1Ref, WeakReference<Spillable> o2Ref) {
                    Spillable o1 = o1Ref.get();
                    Spillable o2 = o2Ref.get();
                    if (o1 == null && o2 == null) {
                        return 0;
                    }
                    if (o1 == null) {
                        return 1;
                    }
                    if (o2 == null) {
                        return -1;
                    }
                    long o1Size = o1.getMemorySize();
                    long o2Size = o2.getMemorySize();
               
                    if (o1Size == o2Size) {
                        return 0;
                    }
                    if (o1Size < o2Size) {
                        return 1;
                    }
                    return -1;
                }
            });
            long estimatedFreed = 0;
            int numObjSpilled = 0;
            boolean invokeGC = false;
            for (Iterator<WeakReference<Spillable>> i = spillables.iterator(); i.hasNext();) {
                Spillable s = i.next().get();
                // Still need to check for null here, even after we removed
                // above, because the reference may have gone bad on us
                // since the last check.
                if (s == null) {
                    i.remove();
                    continue;
                }
                long toBeFreed = s.getMemorySize();
                log.debug("Memorysize = "+toBeFreed+", spillFilesizethreshold = "+spillFileSizeThreshold+", gcactivationsize = "+gcActivationSize);
                // Don't keep trying if the rest of files are too small
                if (toBeFreed < spillFileSizeThreshold) {
                    log.debug("spilling small files - getting out of memory handler");
                    break ;
                }
                s.spill();              
                numObjSpilled++;
                estimatedFreed += toBeFreed;
                accumulatedFreeSize += toBeFreed;
                // This should significantly reduce the number of small files
                // in case that we have a lot of nested bags
                if (accumulatedFreeSize > gcActivationSize) {
                    invokeGC = true;
                }
               
                if (estimatedFreed > toFree) {
                    log.debug("Freed enough space - getting out of memory handler");
                    invokeGC = true;
                    break;
                }
            }          
            /* Poke the GC again to see if we successfully freed enough memory */
            if(invokeGC) {
                System.gc();
                // now that we have invoked the GC, reset accumulatedFreeSize
                accumulatedFreeSize = 0;
            }
            if(estimatedFreed > 0){
                String msg = "Spilled an estimate of " + estimatedFreed +
                " bytes from " + numObjSpilled + " objects. " + info.getUsage();;
                log.info(msg);
            }

        }
    }
View Full Code Here

Examples of java.lang.management.MemoryNotificationInfo

        Notification notif = new Notification(notifType,
                                              getObjectName(),
                                              getNextSeqNumber(),
                                              timestamp,
                                              msg);
        MemoryNotificationInfo info =
            new MemoryNotificationInfo(poolName,
                                       usage,
                                       count);
        CompositeData cd =
            MemoryNotifInfoCompositeData.toCompositeData(info);
        notif.setUserData(cd);
View Full Code Here

Examples of java.lang.management.MemoryNotificationInfo

        CompositeData cd =
            new CompositeDataSupport(ct,
                                     validItemNames,
                                     values);

        MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
        if (!info.getPoolName().equals(values[POOL_NAME])) {
            throw new RuntimeException("pool name = " + info.getPoolName() +
               " expected = " + values[POOL_NAME]);
        }
        if (info.getCount() != ((Long) values[COUNT]).longValue()) {
            throw new RuntimeException("count = " + info.getCount() +
               " expected = " + values[COUNT]);
        }
        if (info.getUsage().getInit() != 0) {
            throw new RuntimeException("usage init = " +
               info.getUsage().getInit() +
               " expected = 0");
        }
        if (info.getUsage().getUsed() != 100) {
            throw new RuntimeException("usage used = " +
               info.getUsage().getUsed() +
               " expected = 100");
        }
        if (info.getUsage().getCommitted () != 1000) {
            throw new RuntimeException("usage committed = " +
               info.getUsage().getCommitted() +
               " expected = 1000");
        }
        if (info.getUsage().getMax() != 5000) {
            throw new RuntimeException("usage max = " +
               info.getUsage().getMax() +
               " expected = 5000");
        }
        System.out.print("Pool name = " + info.getPoolName());
        System.out.println(" Count = " + info.getCount());
        System.out.println("Usage = " + info.getUsage());
    }
View Full Code Here

Examples of java.lang.management.MemoryNotificationInfo

            new CompositeDataSupport(ct,
                                     badItemNames,
                                     values);

        try {
            MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
        } catch (IllegalArgumentException e) {
            System.out.println("Expected exception: " +
                e.getMessage());
            return;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.