All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.schlichtherle.truezip.fs.inst.InstrumentingIOPool Maven / Gradle / Ivy

Go to download

This module provides a file system manager and an I/O pool service for managing and monitoring TrueZIP via JMX and java.util.logging. Add the JAR artifact of this module to the run time class path to make its services available for service location in the client API modules.

The newest version!
/*
 * Copyright (C) 2005-2015 Schlichtherle IT Services.
 * All rights reserved. Use is subject to license terms.
 */
package de.schlichtherle.truezip.fs.inst;

import de.schlichtherle.truezip.entry.DecoratingEntry;
import de.schlichtherle.truezip.socket.IOPool;
import de.schlichtherle.truezip.socket.IOPool.Entry;
import de.schlichtherle.truezip.socket.InputSocket;
import de.schlichtherle.truezip.socket.OutputSocket;
import java.io.IOException;
import javax.annotation.concurrent.Immutable;

/**
 * @param    the type of the I/O buffers.
 * @param    the type of the instrumenting director.
 * @author  Christian Schlichtherle
 */
@Immutable
public class InstrumentingIOPool<
        E extends Entry,
        D extends InstrumentingDirector>
implements IOPool {

    protected final D director;
    protected final IOPool delegate;

    public InstrumentingIOPool(final IOPool pool, final D director) {
        if (null == pool || null == director)
            throw new NullPointerException();
        this.director = director;
        this.delegate = pool;
    }

    @Override
    public Entry allocate() throws IOException {
        return new Buffer(delegate.allocate());
    }

    @Override
    public void release(Entry resource) throws IOException {
        resource.release();
    }

    @Override
    public String toString() {
        return String.format("%s[delegate=%s]", getClass().getName(), delegate);
    }

    @SuppressWarnings("PublicInnerClass")
    public class Buffer
    extends DecoratingEntry>
    implements Entry {

        protected Buffer(Entry delegate) {
            super(delegate);
        }

        @Override
        public InputSocket getInputSocket() {
            return director.instrument(delegate.getInputSocket(), this);
        }

        @Override
        public OutputSocket getOutputSocket() {
            return director.instrument(delegate.getOutputSocket(), this);
        }

        @Override
        public void release() throws IOException {
            delegate.release();
        }
    } // Buffer
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy