de.schlichtherle.truezip.extension.pace.PaceController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truezip-extension-pace Show documentation
Show all versions of truezip-extension-pace Show documentation
This module constrains the number of mounted archive files in order to
save some heap space.
It provides a JMX interface for monitoring and management.
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.
/*
* Copyright (C) 2005-2015 Schlichtherle IT Services.
* All rights reserved. Use is subject to license terms.
*/
package de.schlichtherle.truezip.extension.pace;
import de.schlichtherle.truezip.entry.Entry;
import de.schlichtherle.truezip.entry.Entry.Access;
import de.schlichtherle.truezip.entry.Entry.Type;
import de.schlichtherle.truezip.fs.*;
import de.schlichtherle.truezip.rof.ReadOnlyFile;
import de.schlichtherle.truezip.socket.DecoratingInputSocket;
import de.schlichtherle.truezip.socket.DecoratingOutputSocket;
import de.schlichtherle.truezip.socket.InputSocket;
import de.schlichtherle.truezip.socket.OutputSocket;
import de.schlichtherle.truezip.util.BitField;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.SeekableByteChannel;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Calls back the given {@link PaceManagerController} before and after each
* file system operation in order to
* {@linkplain PaceManagerController#sync sync} the least recently accessed
* file systems which exceed the property
* {@link PaceManagerModel#getMaximumFileSystemsMounted()}
* and register itself as the most recently accessed file system.
*
* @author Christian Schlichtherle
*/
@Immutable
final class PaceController
extends FsDecoratingController> {
private final PaceManagerController manager;
PaceController(
final PaceManagerController manager,
final FsController> controller) {
super(controller);
assert null != manager;
assert null != controller.getParent();
this.manager = manager;
}
@Override
public boolean isReadOnly() throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
return c.isReadOnly();
} finally {
manager.accessed(c);
}
}
@Override
public FsEntry getEntry(FsEntryName name) throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
return c.getEntry(name);
} finally {
manager.accessed(c);
}
}
@Override
public boolean isReadable(FsEntryName name) throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
return c.isReadable(name);
} finally {
manager.accessed(c);
}
}
@Override
public boolean isWritable(FsEntryName name) throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
return c.isWritable(name);
} finally {
manager.accessed(c);
}
}
@Override
public boolean isExecutable(FsEntryName name) throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
return c.isExecutable(name);
} finally {
manager.accessed(c);
}
}
@Override
public void setReadOnly(FsEntryName name) throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
c.setReadOnly(name);
} finally {
manager.accessed(c);
}
}
@Override
public boolean setTime(FsEntryName name, Map times, BitField options) throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
return c.setTime(name, times, options);
} finally {
manager.accessed(c);
}
}
@Override
public boolean setTime(FsEntryName name, BitField types, long value, BitField options) throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
return c.setTime(name, types, value, options);
} finally {
manager.accessed(c);
}
}
@Override
public InputSocket> getInputSocket(
final FsEntryName name,
final BitField options) {
@NotThreadSafe
final class Input extends DecoratingInputSocket {
Input() { super(delegate.getInputSocket(name, options)); }
@Override
public Entry getLocalTarget() throws IOException {
final FsController extends FsModel> c = PaceController.this.delegate;
manager.retain(c);
try {
return getBoundSocket().getLocalTarget();
} finally {
manager.accessed(c);
}
}
@Override
public ReadOnlyFile newReadOnlyFile() throws IOException {
final FsController extends FsModel> c = PaceController.this.delegate;
manager.retain(c);
try {
return getBoundSocket().newReadOnlyFile();
} finally {
manager.accessed(c);
}
}
@Override
public SeekableByteChannel newSeekableByteChannel() throws IOException {
final FsController extends FsModel> c = PaceController.this.delegate;
manager.retain(c);
try {
return getBoundSocket().newSeekableByteChannel();
} finally {
manager.accessed(c);
}
}
@Override
public InputStream newInputStream() throws IOException {
final FsController extends FsModel> c = PaceController.this.delegate;
manager.retain(c);
try {
return getBoundSocket().newInputStream();
} finally {
manager.accessed(c);
}
}
} // Input
return new Input();
}
@Override
public OutputSocket> getOutputSocket(
final FsEntryName name,
final BitField options,
final Entry template) {
@NotThreadSafe
final class Output extends DecoratingOutputSocket {
Output() { super(delegate.getOutputSocket(name, options, template)); }
@Override
public Entry getLocalTarget() throws IOException {
final FsController extends FsModel> c = PaceController.this.delegate;
manager.retain(c);
try {
return getBoundSocket().getLocalTarget();
} finally {
manager.accessed(c);
}
}
@Override
public SeekableByteChannel newSeekableByteChannel() throws IOException {
final FsController extends FsModel> c = PaceController.this.delegate;
manager.retain(c);
try {
return getBoundSocket().newSeekableByteChannel();
} finally {
manager.accessed(c);
}
}
@Override
public OutputStream newOutputStream() throws IOException {
final FsController extends FsModel> c = PaceController.this.delegate;
manager.retain(c);
try {
return getBoundSocket().newOutputStream();
} finally {
manager.accessed(c);
}
}
} // Output
return new Output();
}
@Override
public void mknod(FsEntryName name, Type type, BitField options, Entry template) throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
c.mknod(name, type, options, template);
} finally {
manager.accessed(c);
}
}
@Override
public void unlink(FsEntryName name, BitField options) throws IOException {
final FsController extends FsModel> c = this.delegate;
manager.retain(c);
try {
c.unlink(name, options);
} finally {
manager.accessed(c);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy