001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.caching;
017:
018: import org.geotools.data.DataStore;
019: import org.geotools.data.FeatureReader;
020: import org.geotools.data.FeatureSource;
021: import org.geotools.data.FeatureWriter;
022: import org.geotools.data.LockingManager;
023: import org.geotools.data.Query;
024: import org.geotools.data.Transaction;
025:
026: import org.geotools.feature.FeatureType;
027: import org.geotools.feature.SchemaException;
028:
029: import org.opengis.filter.Filter;
030:
031: import java.io.IOException;
032:
033: /**
034: * @author crousson
035: */
036: public class DelayedDataStore implements DataStore {
037: private final DataStore sourceDataStore;
038: private long msResponseDelay;
039:
040: public DelayedDataStore(DataStore sourceDataStore) {
041: this .sourceDataStore = sourceDataStore;
042: this .msResponseDelay = 0;
043: }
044:
045: public DelayedDataStore(DataStore sourceDataStore,
046: long msResponseDelay) {
047: this .sourceDataStore = sourceDataStore;
048: this .msResponseDelay = msResponseDelay;
049: }
050:
051: /**
052: * @param msResponseDelay the msResponseDelay to set
053: * @uml.property name="msResponseDelay"
054: */
055: public void setMsResponseDelay(long ms) {
056: this .msResponseDelay = ms;
057: }
058:
059: public long getMsReponseDelay() {
060: return this .msResponseDelay;
061: }
062:
063: private synchronized void idle() {
064: try {
065: this .wait(this .msResponseDelay);
066: } catch (InterruptedException e) {
067: // do nothing
068: e.printStackTrace();
069: }
070: }
071:
072: public void createSchema(FeatureType arg0) throws IOException {
073: this .sourceDataStore.createSchema(arg0);
074: }
075:
076: public FeatureReader getFeatureReader(Query arg0, Transaction arg1)
077: throws IOException {
078: idle();
079:
080: return this .sourceDataStore.getFeatureReader(arg0, arg1);
081: }
082:
083: public FeatureSource getFeatureSource(String arg0)
084: throws IOException {
085: idle();
086:
087: return this .sourceDataStore.getFeatureSource(arg0);
088: }
089:
090: public FeatureWriter getFeatureWriter(String arg0, Transaction arg1)
091: throws IOException {
092: idle();
093:
094: return this .sourceDataStore.getFeatureWriter(arg0, arg1);
095: }
096:
097: public FeatureWriter getFeatureWriter(String arg0, Filter arg1,
098: Transaction arg2) throws IOException {
099: idle();
100:
101: return this .sourceDataStore.getFeatureWriter(arg0, arg1, arg2);
102: }
103:
104: public FeatureWriter getFeatureWriterAppend(String arg0,
105: Transaction arg1) throws IOException {
106: idle();
107:
108: return this .sourceDataStore.getFeatureWriterAppend(arg0, arg1);
109: }
110:
111: public LockingManager getLockingManager() {
112: return this .sourceDataStore.getLockingManager();
113: }
114:
115: public FeatureType getSchema(String arg0) throws IOException {
116: return this .sourceDataStore.getSchema(arg0);
117: }
118:
119: public String[] getTypeNames() throws IOException {
120: return this .sourceDataStore.getTypeNames();
121: }
122:
123: public FeatureSource getView(Query arg0) throws IOException,
124: SchemaException {
125: idle();
126:
127: return this .sourceDataStore.getView(arg0);
128: }
129:
130: public void updateSchema(String arg0, FeatureType arg1)
131: throws IOException {
132: this.sourceDataStore.updateSchema(arg0, arg1);
133: }
134: }
|