001: package vicazh.hyperpool.stream;
002:
003: import java.io.*;
004: import vicazh.hyperpool.Start;
005:
006: /**
007: * The record service
008: *
009: * @author Victor Zhigunov
010: * @version 0.4.0
011: */
012: public class RecordService extends FileService implements
013: RecordServiceMBean, Serializable {
014: public RecordService() {
015: }
016:
017: String client;
018:
019: String server;
020:
021: /**
022: * @param cachesize
023: * cache size
024: * @param client
025: * client file extension
026: * @param server
027: * server file extension
028: */
029: public RecordService(int cachesize, String client, String server) {
030: super (cachesize);
031: this .client = client;
032: this .server = server;
033: }
034:
035: private long size;
036:
037: public void setSize(long size) {
038: if (getDir() != null && this .size != size) {
039: this .size = size;
040: pack();
041: } else
042: this .size = size;
043: }
044:
045: public long getSize() {
046: return size;
047: }
048:
049: public Connection getConnection() {
050: return new RecordConnection(this );
051: }
052:
053: public boolean checkPut(File file) {
054: return true;
055: }
056:
057: protected long receive;
058:
059: public boolean checkRemove(File file) {
060: return (receive > size * 1048576L);
061: }
062:
063: synchronized protected void add(File file) {
064: receive += file.length();
065: Start.logger.finest("receive:" + receive);
066: }
067:
068: protected void put(File file) {
069: super .put(file);
070: add(file);
071: }
072:
073: synchronized public void remove(File file) {
074: super .remove(file);
075: receive -= file.length();
076: Start.logger.finest("receive:" + receive);
077: }
078:
079: synchronized protected void fill() {
080: if (size == Long.MAX_VALUE)
081: return;
082: receive = 0;
083: super .fill();
084: }
085:
086: synchronized protected void clear() {
087: super .clear();
088: receive = 0;
089: }
090:
091: public void setAttribute(String name, Object value)
092: throws Exception {
093: if (name.equals(FileServiceMBean.OPTIONS))
094: setSize(((RecordService) value).getSize());
095: super .setAttribute(name, value);
096: }
097:
098: protected FileData getFileData() {
099: return new RecordData(super.getFileData().isDirExists, receive);
100: }
101:
102: }
|