This adds a wrapper OutputStream class for remote access to the AVM. It

also exports AVMSyncService remotely.  (For our friends at Eye Street).


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4316 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-11-08 17:24:00 +00:00
parent a0a304d900
commit c6221ca8a5
4 changed files with 220 additions and 23 deletions

View File

@@ -185,6 +185,20 @@
</property> </property>
</bean> </bean>
<bean id="avmRemoteSyncService" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service">
<ref bean="AVMSyncService"/>
</property>
<property name="serviceInterface">
<value>org.alfresco.service.cmr.avmsync.AVMSyncService</value>
</property>
<property name="serviceName">
<value>avmsync</value>
</property>
<property name="registryPort">
<value>${avm.remote.port}</value>
</property>
</bean>
</beans> </beans>

View File

@@ -4,7 +4,7 @@
<beans> <beans>
<!-- RMI Proxy bean. --> <!-- RMI Proxy bean for avmRemote -->
<bean id="avmRemote" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <bean id="avmRemote" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl"> <property name="serviceUrl">
@@ -18,4 +18,18 @@
</property> </property>
</bean> </bean>
<!-- RMI Proxy bean for avmSync -->
<bean id="avmSync" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl">
<value>rmi://localhost:1313/avmsync</value>
</property>
<property name="serviceInterface">
<value>org.alfresco.service.cmr.avmsync.AVMSyncService</value>
</property>
<property name="refreshStubOnConnectFailure">
<value>true</value>
</property>
</bean>
</beans> </beans>

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C) 2006 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.avm;
import java.io.IOException;
import java.io.OutputStream;
public class AVMRemoteOutputStream extends OutputStream
{
private AVMRemote fAVMRemote;
private String fHandle;
/**
* Create a new one.
* @param handle The handle returned from an AVMRemote call.
* @param remote The AVMRemote instance.
*/
public AVMRemoteOutputStream(String handle, AVMRemote remote)
{
fAVMRemote = remote;
fHandle = handle;
}
/**
* Write one character.
* @param b The character.
*/
@Override
public void write(int b)
throws IOException
{
byte [] buff = new byte[1];
buff[0] = (byte)b;
write(buff);
}
/**
* Close the stream.
*/
@Override
public void close()
throws IOException
{
try
{
fAVMRemote.closeOutputHandle(fHandle);
}
catch (Exception e)
{
throw new IOException("IO Error: " + e);
}
}
/**
* Write a portion of a block of bytes.
* @param b The buffer containing the data.
* @param off The offset into the buffer.
* @param len The number of bytes to write.
*/
@Override
public void write(byte[] b, int off, int len)
throws IOException
{
try
{
if (off == 0)
{
fAVMRemote.writeOutput(fHandle, b, len);
}
else
{
byte [] buff = new byte[len];
for (int i = 0; i < len; i++)
{
buff[i] = b[i + off];
}
fAVMRemote.writeOutput(fHandle, buff, len);
}
}
catch (Exception e)
{
throw new IOException("IO Error: " + e);
}
}
/**
* Write a buffer of data.
* @param b The buffer.
*/
@Override
public void write(byte[] b)
throws IOException
{
write(b, 0, b.length);
}
}

View File

@@ -20,6 +20,8 @@ package org.alfresco.repo.avm;
import java.util.List; import java.util.List;
import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext;
import junit.framework.TestCase; import junit.framework.TestCase;
@@ -35,6 +37,11 @@ public class AVMTestRemote extends TestCase
*/ */
private AVMRemote fAVMRemote; private AVMRemote fAVMRemote;
/**
* The Sync service.
*/
private AVMSyncService fAVMSync;
/** /**
* The application context. * The application context.
*/ */
@@ -45,11 +52,17 @@ public class AVMTestRemote extends TestCase
{ {
fContext = new FileSystemXmlApplicationContext("config/alfresco/remote-avm-test-context.xml"); fContext = new FileSystemXmlApplicationContext("config/alfresco/remote-avm-test-context.xml");
fAVMRemote = (AVMRemote)fContext.getBean("avmRemote"); fAVMRemote = (AVMRemote)fContext.getBean("avmRemote");
fAVMSync = (AVMSyncService)fContext.getBean("avmSync");
} }
@Override @Override
protected void tearDown() throws Exception protected void tearDown() throws Exception
{ {
List<AVMStoreDescriptor> stores = fAVMRemote.getAVMStores();
for (AVMStoreDescriptor desc : stores)
{
fAVMRemote.purgeAVMStore(desc.getName());
}
fContext.close(); fContext.close();
} }
@@ -61,7 +74,6 @@ public class AVMTestRemote extends TestCase
try try
{ {
List<AVMStoreDescriptor> stores = fAVMRemote.getAVMStores(); List<AVMStoreDescriptor> stores = fAVMRemote.getAVMStores();
assertTrue(stores.size() > 0);
for (AVMStoreDescriptor store : stores) for (AVMStoreDescriptor store : stores)
{ {
System.out.println(store); System.out.println(store);
@@ -81,21 +93,27 @@ public class AVMTestRemote extends TestCase
{ {
try try
{ {
// Create a directory. // Create a test store.
fAVMRemote.createDirectory("main:/", "a"); fAVMRemote.createAVMStore("test2933");
// Write out a file. // Create a directory.
String outHandle = fAVMRemote.createFile("main:/a", "foo.txt"); fAVMRemote.createDirectory("test2933:/", "a");
byte [] buff = "This is a plain old text file.\n".getBytes(); // Write out a file.
fAVMRemote.writeOutput(outHandle, buff, buff.length); AVMRemoteOutputStream out =
buff = "It contains text.\n".getBytes(); new AVMRemoteOutputStream(fAVMRemote.createFile("test2933:/a", "foo.txt"),
fAVMRemote.writeOutput(outHandle, buff, buff.length); fAVMRemote);
fAVMRemote.closeOutputHandle(outHandle); byte [] buff = "This is a plain old text file.\n".getBytes();
// Read back that file. out.write(buff);
String inHandle = fAVMRemote.getInputHandle(-1, "main:/a/foo.txt"); buff = "It contains text.\n".getBytes();
buff = fAVMRemote.readInput(inHandle, 1024); out.write(buff);
fAVMRemote.closeInputHandle(inHandle); out.close();
System.out.print(new String(buff)); // Read back that file.
fAVMRemote.removeNode("main:/", "a"); AVMRemoteInputStream in =
new AVMRemoteInputStream(fAVMRemote.getInputHandle(-1, "test2933:/a/foo.txt"),
fAVMRemote);
buff = new byte[1024];
assertEquals(49, in.read(buff));
System.out.print(new String(buff));
assertEquals(-1, in.read(buff));
} }
catch (Exception e) catch (Exception e)
{ {
@@ -111,19 +129,25 @@ public class AVMTestRemote extends TestCase
{ {
try try
{ {
fAVMRemote.createAVMStore("froo");
// Create a file. // Create a file.
byte [] buff = new byte[64]; byte [] buff = new byte[64];
for (int i = 0; i < 64; i++) for (int i = 0; i < 64; i++)
{ {
buff[i] = (byte)i; buff[i] = (byte)i;
} }
String outHandle = fAVMRemote.createFile("main:/", "foo.dat"); AVMRemoteOutputStream out =
fAVMRemote.writeOutput(outHandle, buff, 64); new AVMRemoteOutputStream(fAVMRemote.createFile("froo:/", "foo.dat"),
fAVMRemote.closeOutputHandle(outHandle); fAVMRemote);
out.write(buff, 32, 32);
out.close();
// Read it back in. // Read it back in.
String inHandle = fAVMRemote.getInputHandle(-1, "main:/foo.dat"); AVMRemoteInputStream in =
buff = fAVMRemote.readInput(inHandle, 64); new AVMRemoteInputStream(fAVMRemote.getInputHandle(-1, "froo:/foo.dat"),
fAVMRemote.closeInputHandle(inHandle); fAVMRemote);
buff = new byte[1024];
assertEquals(32, in.read(buff));
in.close();
} }
catch (Exception e) catch (Exception e)
{ {
@@ -147,4 +171,38 @@ public class AVMTestRemote extends TestCase
fail(); fail();
} }
} }
/**
* Test the sync service.
*/
public void testSyncService()
{
try
{
// Create a store.
fAVMRemote.createAVMStore("froo");
// Create a directory.
fAVMRemote.createDirectory("froo:/", "a");
// Create a file.
fAVMRemote.closeOutputHandle(fAVMRemote.createFile("froo:/a", "foo"));
// Create another store.
fAVMRemote.createAVMStore("broo");
// Create a branch.
fAVMRemote.createBranch(-1, "froo:/a", "broo:/", "a");
List<AVMDifference> diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a");
assertEquals(0, diffs.size());
fAVMRemote.closeOutputHandle(fAVMRemote.createFile("froo:/a", "bar"));
diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a");
assertEquals(1, diffs.size());
// Update.
fAVMSync.update(diffs, false, false, false, false, "flippy", "Stuff");
diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a");
assertEquals(0, diffs.size());
}
catch (Exception e)
{
e.printStackTrace();
fail();
}
}
} }