VolD 0.1

RESTVoldReplicator.java

Go to the documentation of this file.
00001 
00002 package de.zib.vold.replication;
00003 
00004 import de.zib.vold.client.RESTClient;
00005 import de.zib.vold.common.Key;
00006 
00007 import java.util.List;
00008 import java.util.Set;
00009 import java.util.HashSet;
00010 
00011 import org.slf4j.Logger;
00012 import org.slf4j.LoggerFactory;
00013 
00026 public class RESTVoldReplicator implements Replicator
00027 {
00028         protected final Logger log = LoggerFactory.getLogger( this.getClass() );
00029 
00030         RESTClient rest;
00031 
00035         public RESTVoldReplicator( )
00036         {
00037                 this.rest = new RESTClient();
00038         }
00039 
00043         public void setBaseURL( String baseURL )
00044         {
00045                 rest.setBaseURL( baseURL );
00046         }
00047 
00051         public void checkState( )
00052         {
00053                 try
00054                 {
00055                         rest.checkState();
00056                 }
00057                 catch( IllegalStateException e )
00058                 {
00059                         throw new IllegalStateException( "Tried to operate on RESTReplicator while it had not been initialized yet. Set restClient before!", e );
00060                 }
00061         }
00062 
00069         @Override
00070         public void insert( List< String > key, Set< String > value )
00071         {
00072                 // guard
00073                 {
00074                         if( 4 != key.size() )
00075                         {
00076                                 throw new IllegalArgumentException( "key does not seem to come from Frontend." );
00077                         }
00078 
00079                         log.trace( "Insert: " + key.toString() + " |--> " + value.toString() );
00080 
00081                         checkState();
00082                 }
00083 
00084                 // build key
00085                 Key k;
00086                 {
00087                         k = Key.buildkey( key );
00088                 }
00089 
00090                 rest.insert( key.get( 3 ), k, value );
00091         }
00092 
00098         @Override
00099         public void refresh( List< String > key )
00100         {
00101                 // guard
00102                 {
00103                         if( 4 != key.size() )
00104                         {
00105                                 throw new IllegalArgumentException( "key does not seem to come from Frontend." );
00106                         }
00107 
00108                         log.trace( "Refresh: " + key.toString() );
00109 
00110                         checkState();
00111                 }
00112 
00113                 // build key
00114                 Key k;
00115                 {
00116                         k = Key.buildkey( key );
00117                 }
00118 
00119                 Set< Key > keys = new HashSet< Key >();
00120                 keys.add( k );
00121 
00122                 rest.refresh( key.get( 3 ), keys );
00123         }
00124 
00130         @Override
00131         public void delete( List< String > key )
00132         {
00133                 // no need to remove that key - that is part of the other VolD service
00134         }
00135 }