package org.apache.felix.ipojo.everest.system;

import org.apache.felix.ipojo.everest.impl.DefaultReadOnlyResource;
import org.apache.felix.ipojo.everest.impl.ImmutableResourceMetadata;
import org.apache.felix.ipojo.everest.services.Path;
import org.apache.felix.ipojo.everest.services.ResourceMetadata;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;

import static org.apache.felix.ipojo.everest.system.SystemRootResource.SYSTEM_ROOT_PATH;

/**
 * Created with IntelliJ IDEA.
 * User: ozan
 * Date: 5/28/13
 * Time: 1:42 PM
 */
public class MemoryResource extends DefaultReadOnlyResource {

    private static final Path MEMORY_PATH = SYSTEM_ROOT_PATH.addElements("memory");

    private final MemoryMXBean m_memoryMXBean;

    private static final MemoryResource instance = new MemoryResource();

    public static MemoryResource getInstance() {
        return instance;
    }

    public MemoryResource() {
        super(MEMORY_PATH);
        m_memoryMXBean = ManagementFactory.getMemoryMXBean();
    }

    @Override
    public ResourceMetadata getMetadata() {
        ImmutableResourceMetadata.Builder metadataBuilder = new ImmutableResourceMetadata.Builder();
        metadataBuilder.set("used-heap", m_memoryMXBean.getHeapMemoryUsage().getUsed());
        metadataBuilder.set("commited-heap", m_memoryMXBean.getHeapMemoryUsage().getCommitted());
        metadataBuilder.set("used-nonheap", m_memoryMXBean.getNonHeapMemoryUsage().getUsed());
        metadataBuilder.set("commited-nonheap", m_memoryMXBean.getNonHeapMemoryUsage().getCommitted());
        metadataBuilder.set("verbose", m_memoryMXBean.isVerbose());
        return metadataBuilder.build();
    }
}



@@ -298,16 +298,37 @@
 adata;%0A%0A
+import java.io.File;%0A
 import j
@@ -1673,24 +1673,257 @@
 Verbose());%0A
+        File file = new File(%22/%22);%0A        metadataBuilder.set(%22total-space%22, file.getTotalSpace());%0A        metadataBuilder.set(%22free-space%22, file.getFreeSpace());%0A        metadataBuilder.set(%22usable-space%22, file.getUsableSpace());%0A
         retu

add of system fs size