brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] incubator-brooklyn git commit: Adds PersistenceObjectStore.StoreObjectAccessor.getBytes
Date Thu, 26 Mar 2015 11:03:26 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 7b5c75495 -> 4c8840e17


Adds PersistenceObjectStore.StoreObjectAccessor.getBytes

Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/2914f042
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/2914f042
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/2914f042

Branch: refs/heads/master
Commit: 2914f0420b861f6abaa4fcca14d80ab7ced2bc92
Parents: 7b5c754
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Mar 25 16:31:18 2015 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Mar 25 16:31:18 2015 +0000

----------------------------------------------------------------------
 .../persister/FileBasedStoreObjectAccessor.java | 10 +++++++++
 .../persister/PersistenceObjectStore.java       |  1 +
 .../persister/StoreObjectAccessorLocking.java   | 18 ++++++++++++++++
 .../rebind/persister/InMemoryObjectStore.java   |  4 ++++
 .../rebind/persister/ListeningObjectStore.java  |  4 ++++
 .../jclouds/JcloudsStoreObjectAccessor.java     | 22 ++++++++++++++++++++
 6 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2914f042/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessor.java
b/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessor.java
index acaf660..c7622d6 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessor.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessor.java
@@ -62,6 +62,16 @@ public class FileBasedStoreObjectAccessor implements PersistenceObjectStore.Stor
     }
 
     @Override
+    public byte[] getBytes() {
+        try {
+            if (!exists()) return null;
+            return Files.asByteSource(file).read();
+        } catch (IOException e) {
+            throw Throwables.propagate(e);
+        }
+    }
+
+    @Override
     public boolean exists() {
         return file.exists();
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2914f042/core/src/main/java/brooklyn/entity/rebind/persister/PersistenceObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/PersistenceObjectStore.java
b/core/src/main/java/brooklyn/entity/rebind/persister/PersistenceObjectStore.java
index 9fd4fb9..ffefcd3 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/PersistenceObjectStore.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/PersistenceObjectStore.java
@@ -39,6 +39,7 @@ public interface PersistenceObjectStore {
     public interface StoreObjectAccessor {
         /** gets the object, or null if not found */
         String get();
+        byte[] getBytes();
         boolean exists();
         void put(String contentsToReplaceOrCreate);
         void append(String contentsToAppendOrCreate);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2914f042/core/src/main/java/brooklyn/entity/rebind/persister/StoreObjectAccessorLocking.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/StoreObjectAccessorLocking.java
b/core/src/main/java/brooklyn/entity/rebind/persister/StoreObjectAccessorLocking.java
index 9958597..033233b 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/StoreObjectAccessorLocking.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/StoreObjectAccessorLocking.java
@@ -83,6 +83,24 @@ public class StoreObjectAccessorLocking implements PersistenceObjectStore.StoreO
     }
 
     @Override
+    public byte[] getBytes() {
+        try {
+            queuedReaders.add(Thread.currentThread());
+            lock.readLock().lockInterruptibly();
+            try {
+                return delegate.getBytes();
+                
+            } finally {
+                lock.readLock().unlock();
+            }
+        } catch (InterruptedException e) {
+            throw Exceptions.propagate(e);
+        } finally {
+            queuedReaders.remove(Thread.currentThread());
+        }
+    }
+
+    @Override
     public boolean exists() {
         try {
             queuedReaders.add(Thread.currentThread());

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2914f042/core/src/test/java/brooklyn/entity/rebind/persister/InMemoryObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/InMemoryObjectStore.java
b/core/src/test/java/brooklyn/entity/rebind/persister/InMemoryObjectStore.java
index 6854bc3..c829369 100644
--- a/core/src/test/java/brooklyn/entity/rebind/persister/InMemoryObjectStore.java
+++ b/core/src/test/java/brooklyn/entity/rebind/persister/InMemoryObjectStore.java
@@ -86,6 +86,10 @@ public class InMemoryObjectStore implements PersistenceObjectStore {
             }
         }
         @Override
+        public byte[] getBytes() {
+            return get().getBytes();
+        }
+        @Override
         public boolean exists() {
             synchronized (map) {
                 return map.containsKey(key);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2914f042/core/src/test/java/brooklyn/entity/rebind/persister/ListeningObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/ListeningObjectStore.java
b/core/src/test/java/brooklyn/entity/rebind/persister/ListeningObjectStore.java
index 65df193..c5ac4ff 100644
--- a/core/src/test/java/brooklyn/entity/rebind/persister/ListeningObjectStore.java
+++ b/core/src/test/java/brooklyn/entity/rebind/persister/ListeningObjectStore.java
@@ -238,6 +238,10 @@ public class ListeningObjectStore implements PersistenceObjectStore {
             return result;
         }
         @Override
+        public byte[] getBytes() {
+            return get().getBytes();
+        }
+        @Override
         public Date getLastModifiedDate() {
             return delegate.getLastModifiedDate();
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2914f042/locations/jclouds/src/main/java/brooklyn/entity/rebind/persister/jclouds/JcloudsStoreObjectAccessor.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/entity/rebind/persister/jclouds/JcloudsStoreObjectAccessor.java
b/locations/jclouds/src/main/java/brooklyn/entity/rebind/persister/jclouds/JcloudsStoreObjectAccessor.java
index 798d166..2e60f7c 100644
--- a/locations/jclouds/src/main/java/brooklyn/entity/rebind/persister/jclouds/JcloudsStoreObjectAccessor.java
+++ b/locations/jclouds/src/main/java/brooklyn/entity/rebind/persister/jclouds/JcloudsStoreObjectAccessor.java
@@ -18,7 +18,9 @@
  */
 package brooklyn.entity.rebind.persister.jclouds;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Date;
 
 import org.apache.commons.io.Charsets;
@@ -31,6 +33,7 @@ import brooklyn.util.exceptions.Exceptions;
 
 import com.google.common.base.Throwables;
 import com.google.common.io.ByteSource;
+import com.google.common.io.ByteStreams;
 
 /**
  * @author Andrea Turli
@@ -97,6 +100,25 @@ public class JcloudsStoreObjectAccessor implements PersistenceObjectStore.StoreO
     }
 
     @Override
+    public byte[] getBytes() {
+        try {
+            Blob blob = blobStore.getBlob(containerName, blobName);
+            if (blob==null) return null;
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            InputStream in = blob.getPayload().openStream();
+            try {
+                ByteStreams.copy(in, out);
+                return out.toByteArray();
+            } finally {
+                out.close();
+            }
+        } catch (IOException e) {
+            Exceptions.propagateIfFatal(e);
+            throw new IllegalStateException("Error reading blobstore "+containerName+" "+blobName+":
"+e, e);
+        }
+    }
+
+    @Override
     public Date getLastModifiedDate() {
         Blob blob = blobStore.getBlob(containerName, blobName);
         if (blob==null) return null;


Mime
View raw message