Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/CDOProtocolImpl.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java2
-rw-r--r--plugins/org.eclipse.net4j.examples/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadClientAction.java4
-rw-r--r--plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadProtocol.java24
-rw-r--r--plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadServer.java170
-rw-r--r--plugins/org.eclipse.net4j.jms.admin/src/org/eclipse/net4j/jms/internal/admin/protocol/JMSAdminProtocol.java13
-rw-r--r--plugins/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientProtocol.java8
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java15
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java9
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.java34
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java13
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java10
13 files changed, 260 insertions, 49 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/CDOProtocolImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/CDOProtocolImpl.java
index 6b01384ab4..604df8a4b6 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/CDOProtocolImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/CDOProtocolImpl.java
@@ -24,11 +24,7 @@ public abstract class CDOProtocolImpl extends SignalProtocol<CDOProtocolSession>
{
public CDOProtocolImpl()
{
- }
-
- public String getType()
- {
- return CDOProtocolConstants.PROTOCOL_NAME;
+ super(CDOProtocolConstants.PROTOCOL_NAME);
}
public CDOProtocolSession getSession()
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
index 7346e29f2e..f0cd561dc8 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
@@ -125,7 +125,7 @@ public class CDOServerProtocol extends CDOProtocolImpl
return new ObjectLockedIndication(this);
default:
- return null;
+ return super.createSignalReactor(signalID);
}
}
}
diff --git a/plugins/org.eclipse.net4j.examples/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.examples/META-INF/MANIFEST.MF
index 575920e24a..8d485c3c7f 100644
--- a/plugins/org.eclipse.net4j.examples/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.examples/META-INF/MANIFEST.MF
@@ -16,4 +16,5 @@ Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.net4j.examples.echo;version="2.0.0",
org.eclipse.net4j.examples.echo.client;version="2.0.0",
org.eclipse.net4j.examples.echo.server;version="2.0.0",
+ org.eclipse.net4j.examples.transfer;version="2.0.0",
org.eclipse.net4j.internal.examples.bundle;version="2.0.0"
diff --git a/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadClientAction.java b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadClientAction.java
index 79f448cd68..8062480c54 100644
--- a/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadClientAction.java
+++ b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadClientAction.java
@@ -34,6 +34,10 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
public class UploadClientAction implements IWorkbenchWindowActionDelegate, UploadProtocol
{
private IWorkbenchWindow window;
diff --git a/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadProtocol.java b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadProtocol.java
new file mode 100644
index 0000000000..7dd4369a7f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadProtocol.java
@@ -0,0 +1,24 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.examples.transfer;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public interface UploadProtocol
+{
+ public static final String PROTOCOL_NAME = "upload";
+
+ public static final short UPLOAD_SIGNAL_ID = 1;
+
+ public static final int BUFFER_SIZE = 8192;
+}
diff --git a/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadServer.java b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadServer.java
new file mode 100644
index 0000000000..853bfcffea
--- /dev/null
+++ b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/transfer/UploadServer.java
@@ -0,0 +1,170 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.examples.transfer;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.internal.examples.bundle.OM;
+import org.eclipse.net4j.signal.IndicationWithMonitoring;
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.signal.SignalReactor;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.util.container.ContainerUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.PrintLogHandler;
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
+
+import org.eclipse.spi.net4j.ServerProtocolFactory;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class UploadServer implements UploadProtocol
+{
+ public static final String FOLDER_NAME = "/temp";
+
+ public static void main(String[] args) throws Exception
+ {
+ // Send all traces and logs to the console
+ OMPlatform.INSTANCE.setDebugging(true);
+ OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+ OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
+
+ // Use this container to create and wire the components
+ IManagedContainer container = ContainerUtil.createContainer();
+
+ try
+ {
+ Net4jUtil.prepareContainer(container);
+ TCPUtil.prepareContainer(container);
+ container.registerFactory(new ProtocolFactory());
+
+ LifecycleUtil.activate(container);
+
+ // Start an acceptor
+ IAcceptor acceptor = (IAcceptor)container.getElement("org.eclipse.net4j.acceptors", "tcp", "0.0.0.0:2036");
+ OM.LOG.info("Accepting connections: " + acceptor);
+
+ new File(FOLDER_NAME).mkdirs();
+ OM.LOG.info("Upload folder: " + FOLDER_NAME);
+
+ System.out.println("Press any key to shutdown");
+ while (System.in.read() == -1)
+ {
+ Thread.sleep(200);
+ }
+ }
+ finally
+ {
+ LifecycleUtil.deactivate(container);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class ProtocolFactory extends ServerProtocolFactory
+ {
+ public ProtocolFactory()
+ {
+ super(PROTOCOL_NAME);
+ }
+
+ public Object create(String description) throws ProductCreationException
+ {
+ return new SignalProtocol<Object>(PROTOCOL_NAME)
+ {
+ @Override
+ protected SignalReactor createSignalReactor(short signalID)
+ {
+ switch (signalID)
+ {
+ case UPLOAD_SIGNAL_ID:
+ return new UploadIndication(this);
+
+ default:
+ return super.createSignalReactor(signalID);
+ }
+ }
+ };
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class UploadIndication extends IndicationWithMonitoring
+ {
+ private boolean replaced;
+
+ public UploadIndication(SignalProtocol<Object> protocol)
+ {
+ super(protocol, UPLOAD_SIGNAL_ID);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in, OMMonitor monitor) throws Exception
+ {
+ long size = in.readLong();
+ String fileName = in.readString();
+ File file = new File(FOLDER_NAME, fileName);
+ replaced = file.exists();
+ System.out.println((replaced ? "Replacing " : "Storing ") + file.getAbsolutePath());
+
+ monitor.begin((int)size);
+ BufferedOutputStream out = null;
+
+ try
+ {
+ out = new BufferedOutputStream(new FileOutputStream(file));
+ while (size != 0L)
+ {
+ int chunk = BUFFER_SIZE;
+ if (size < BUFFER_SIZE)
+ {
+ chunk = (int)size;
+ }
+
+ byte[] buffer = in.readByteArray();
+ out.write(buffer);
+
+ monitor.worked(chunk);
+ size -= chunk;
+ }
+ }
+ finally
+ {
+ monitor.done();
+ if (out != null)
+ {
+ out.close();
+ }
+ }
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception
+ {
+ out.writeBoolean(replaced);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.jms.admin/src/org/eclipse/net4j/jms/internal/admin/protocol/JMSAdminProtocol.java b/plugins/org.eclipse.net4j.jms.admin/src/org/eclipse/net4j/jms/internal/admin/protocol/JMSAdminProtocol.java
index 294f6827f0..5f98c3cdcc 100644
--- a/plugins/org.eclipse.net4j.jms.admin/src/org/eclipse/net4j/jms/internal/admin/protocol/JMSAdminProtocol.java
+++ b/plugins/org.eclipse.net4j.jms.admin/src/org/eclipse/net4j/jms/internal/admin/protocol/JMSAdminProtocol.java
@@ -13,7 +13,6 @@ package org.eclipse.net4j.jms.internal.admin.protocol;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.jms.JMSAdminProtocolConstants;
import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.signal.SignalReactor;
/**
* @author Eike Stepper
@@ -22,17 +21,7 @@ public class JMSAdminProtocol extends SignalProtocol<Object>
{
public JMSAdminProtocol(IConnector connector)
{
+ super(JMSAdminProtocolConstants.PROTOCOL_NAME);
open(connector);
}
-
- public String getType()
- {
- return JMSAdminProtocolConstants.PROTOCOL_NAME;
- }
-
- @Override
- protected SignalReactor createSignalReactor(short signalID)
- {
- return null;
- }
}
diff --git a/plugins/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientProtocol.java b/plugins/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientProtocol.java
index e311349c2b..76219a036f 100644
--- a/plugins/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientProtocol.java
+++ b/plugins/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientProtocol.java
@@ -25,14 +25,10 @@ public class JMSClientProtocol extends SignalProtocol<ConnectionImpl>
*/
public JMSClientProtocol(ConnectionImpl connection)
{
+ super(JMSProtocolConstants.PROTOCOL_NAME);
setInfraStructure(connection);
}
- public String getType()
- {
- return JMSProtocolConstants.PROTOCOL_NAME;
- }
-
@Override
protected SignalReactor createSignalReactor(short signalID)
{
@@ -42,7 +38,7 @@ public class JMSClientProtocol extends SignalProtocol<ConnectionImpl>
return new JMSServerMessageIndication(this);
default:
- return null;
+ return super.createSignalReactor(signalID);
}
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java
index 60815771f2..ba2fcf697a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java
@@ -75,6 +75,7 @@ public abstract class IndicationWithMonitoring extends IndicationWithResponse
{
if (monitor != null)
{
+ monitor.done();
monitor = null;
if (monitorFuture != null)
{
@@ -136,13 +137,14 @@ public abstract class IndicationWithMonitoring extends IndicationWithResponse
});
}
+ monitor.begin(100);
indicating(in, monitor.fork(getIndicatingWorkPercent()));
}
@Override
protected final void responding(ExtendedDataOutputStream out) throws Exception
{
- responding(out, monitor.fork(getRespondingWorkPercent()));
+ responding(out, monitor.fork(100 - getIndicatingWorkPercent()));
}
protected abstract void indicating(ExtendedDataInputStream in, OMMonitor monitor) throws Exception;
@@ -159,12 +161,7 @@ public abstract class IndicationWithMonitoring extends IndicationWithResponse
protected int getIndicatingWorkPercent()
{
- return 50;
- }
-
- protected int getRespondingWorkPercent()
- {
- return 50;
+ return 100;
}
void setMonitorCanceled()
@@ -188,6 +185,10 @@ public abstract class IndicationWithMonitoring extends IndicationWithResponse
*/
private final class LastAccessMonitor extends Monitor
{
+ public LastAccessMonitor()
+ {
+ }
+
@Override
public synchronized void begin(int totalWork)
{
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java
index cd3633ba1a..734ef09a1b 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java
@@ -60,7 +60,7 @@ public abstract class RequestWithConfirmation<RESULT> extends SignalActor
{
public RESULT call() throws Exception
{
- return send();
+ return doSend(getProtocol().getTimeout());
}
});
}
@@ -70,7 +70,7 @@ public abstract class RequestWithConfirmation<RESULT> extends SignalActor
*/
public RESULT send() throws Exception, RemoteException
{
- return send(getProtocol().getTimeout());
+ return doSend(getProtocol().getTimeout());
}
/**
@@ -78,6 +78,11 @@ public abstract class RequestWithConfirmation<RESULT> extends SignalActor
*/
public RESULT send(long timeout) throws Exception, RemoteException
{
+ return doSend(timeout);
+ }
+
+ RESULT doSend(long timeout) throws Exception
+ {
result = null;
getProtocol().startSignal(this, timeout);
return result;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.java
index f786f731d4..7d00d149ea 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.java
@@ -73,25 +73,28 @@ public abstract class RequestWithMonitoring<RESULT> extends RequestWithConfirmat
@Override
public Future<RESULT> sendAsync()
{
- return sendAsync(null);
+ initMainMonitor(null);
+ return super.sendAsync();
}
- @Override
- public RESULT send() throws Exception, RemoteException
+ public Future<RESULT> sendAsync(OMMonitor monitor)
{
- return send(null);
+ initMainMonitor(monitor);
+ return super.sendAsync();
}
@Override
- public RESULT send(long timeout) throws Exception, RemoteException
+ public RESULT send() throws Exception, RemoteException
{
- return send(timeout, null);
+ initMainMonitor(null);
+ return super.send();
}
- public Future<RESULT> sendAsync(OMMonitor monitor)
+ @Override
+ public RESULT send(long timeout) throws Exception, RemoteException
{
- initMainMonitor(monitor);
- return super.sendAsync();
+ initMainMonitor(null);
+ return super.send(timeout);
}
public RESULT send(OMMonitor monitor) throws Exception, RemoteException
@@ -157,7 +160,14 @@ public abstract class RequestWithMonitoring<RESULT> extends RequestWithConfirmat
@Override
protected final RESULT confirming(ExtendedDataInputStream in) throws Exception
{
- return confirming(in, mainMonitor.fork(getConfirmingWorkPercent()));
+ try
+ {
+ return confirming(in, mainMonitor.fork(getConfirmingWorkPercent()));
+ }
+ finally
+ {
+ mainMonitor.done();
+ }
}
protected abstract void requesting(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception;
@@ -197,7 +207,7 @@ public abstract class RequestWithMonitoring<RESULT> extends RequestWithConfirmat
*/
protected int getRequestingWorkPercent()
{
- return 25;
+ return 50;
}
/**
@@ -205,7 +215,7 @@ public abstract class RequestWithMonitoring<RESULT> extends RequestWithConfirmat
*/
protected int getConfirmingWorkPercent()
{
- return 25;
+ return 0;
}
@Override
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java
index 3bc88800ad..968c35c82a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java
@@ -38,7 +38,7 @@ import java.util.Map;
/**
* @author Eike Stepper
*/
-public abstract class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> implements
+public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> implements
ISignalProtocol<INFRA_STRUCTURE>
{
/**
@@ -76,8 +76,12 @@ public abstract class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STR
private boolean failingOver;
- protected SignalProtocol()
+ /**
+ * @since 2.0
+ */
+ public SignalProtocol(String type)
{
+ super(type);
}
/**
@@ -315,7 +319,10 @@ public abstract class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STR
* Returns a new signal instance to serve the given signal ID or <code>null</code> if the signal ID is invalid/unknown
* for this protocol.
*/
- protected abstract SignalReactor createSignalReactor(short signalID);
+ protected SignalReactor createSignalReactor(short signalID)
+ {
+ return null;
+ }
synchronized int getNextCorrelationID()
{
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java
index 19f5212457..76ab51febf 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java
@@ -27,6 +27,8 @@ import java.util.concurrent.ExecutorService;
*/
public abstract class Protocol<INFRA_STRUCTURE> extends Lifecycle implements IProtocol<INFRA_STRUCTURE>
{
+ private String type;
+
private ExecutorService executorService;
private IBufferProvider bufferProvider;
@@ -45,8 +47,14 @@ public abstract class Protocol<INFRA_STRUCTURE> extends Lifecycle implements IPr
};
};
- public Protocol()
+ public Protocol(String type)
+ {
+ this.type = type;
+ }
+
+ public final String getType()
{
+ return type;
}
public ExecutorService getExecutorService()

Back to the top