-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODE-1291 MODE-1581 Updated InfinispanBinaryStore implementation to r…
…eflect recent backup service changes For MODE-1581, a new method was added to the BinaryStore interface to enable the backup service to obtain all of the BinaryKey values from the store. This commit incorporates the change into the now-implemented InfinispanBinaryStore.
- Loading branch information
Showing
18 changed files
with
1,582 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
modeshape-jcr/src/main/java/org/modeshape/jcr/value/binary/infinispan/ChunkInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* ModeShape (http://www.modeshape.org) | ||
* See the COPYRIGHT.txt file distributed with this work for information | ||
* regarding copyright ownership. Some portions may be licensed | ||
* to Red Hat, Inc. under one or more contributor license agreements. | ||
* See the AUTHORS.txt file in the distribution for a full listing of | ||
* individual contributors. | ||
* | ||
* ModeShape is free software. Unless otherwise indicated, all code in ModeShape | ||
* is licensed to you under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* ModeShape is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.modeshape.jcr.value.binary.infinispan; | ||
|
||
import org.infinispan.Cache; | ||
import org.modeshape.common.logging.Logger; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Merges chunks from cache and provides InputStream-feeling. | ||
*/ | ||
class ChunkInputStream extends InputStream { | ||
|
||
private final Logger logger; | ||
private final Cache<String, byte[]> blobCache; | ||
private final String key; | ||
|
||
protected int indexInBuffer; | ||
protected byte[] buffer; | ||
private int chunkNumber; | ||
|
||
|
||
public ChunkInputStream(Cache<String, byte[]> blobCache, String key){ | ||
logger = Logger.getLogger(getClass()); | ||
this.blobCache = blobCache; | ||
this.key = key; | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
if(indexInBuffer == -1){ | ||
return -1; | ||
} | ||
if(buffer == null || indexInBuffer >= buffer.length){ | ||
fillBuffer(); | ||
return read(); | ||
} | ||
return buffer[indexInBuffer++] & 0xff; | ||
} | ||
|
||
@Override | ||
public int read(byte[] b, int off, int len) throws IOException { | ||
if(indexInBuffer == -1){ | ||
return -1; | ||
} | ||
if(buffer == null){ | ||
fillBuffer(); | ||
return read(b, off, len); | ||
} | ||
if(indexInBuffer >= buffer.length){ | ||
return -1; | ||
} | ||
if (indexInBuffer + len > buffer.length){ | ||
len = buffer.length - indexInBuffer; | ||
} | ||
System.arraycopy(buffer, indexInBuffer, b, off, len); | ||
indexInBuffer += len; | ||
if(indexInBuffer >= buffer.length){ | ||
fillBuffer(); | ||
} | ||
return len; | ||
} | ||
|
||
@Override | ||
public int available() { | ||
return buffer.length - indexInBuffer; | ||
} | ||
|
||
@Override | ||
public final long skip(long n) throws IOException { | ||
if(n <= 0 || indexInBuffer == -1){ | ||
return 0; | ||
} | ||
if(buffer == null){ | ||
fillBuffer(); | ||
return skip(n); | ||
} | ||
if (buffer.length + n > indexInBuffer){ | ||
n = buffer.length - indexInBuffer; | ||
} | ||
if (n < 0){ | ||
return 0; | ||
} | ||
indexInBuffer += n; | ||
return n; | ||
} | ||
|
||
private void fillBuffer() throws IOException { | ||
|
||
buffer = nextChunk(); | ||
if(buffer == null){ | ||
buffer = new byte[0]; | ||
indexInBuffer = -1; | ||
} else { | ||
indexInBuffer = 0; | ||
} | ||
} | ||
|
||
protected byte[] nextChunk() throws IOException { | ||
String chunkKey = key+"-"+chunkNumber++; | ||
logger.debug("Read chunk {0}", chunkKey); | ||
return blobCache.get(chunkKey); | ||
} | ||
} |
Oops, something went wrong.