Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-02-18 13:25:16 -0500
committerslewis2009-02-18 13:25:16 -0500
commit36e7362a040d3d3dbbecaa47e3ae62a21ec4ae79 (patch)
tree132cd6944408b2af18de0ead4449607cb8db3fec /providers/bundles/org.eclipse.ecf.provider.filetransfer
parent12ee225f66866485a4d981904ae6f7278bea2ce4 (diff)
downloadorg.eclipse.ecf-36e7362a040d3d3dbbecaa47e3ae62a21ec4ae79.tar.gz
org.eclipse.ecf-36e7362a040d3d3dbbecaa47e3ae62a21ec4ae79.tar.xz
org.eclipse.ecf-36e7362a040d3d3dbbecaa47e3ae62a21ec4ae79.zip
Applied patch 125967 from bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=263613. Adds provisional 'socket' event API to org.eclipse.ecf.filetransfer, plus implementations in org.eclipse.ecf.provider.filetransfer and o.e.e.provider.filetransfer.httpclient. Also adds support for rapid cancellation to httpclient-based browse, and restructures and adds tests. Also requires changing EE for org.eclipse.ecf.provider.filetransfer to CDC 1.1/Foundation 1.1 + JRE 1.4.
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.filetransfer')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/.classpath4
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF6
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java43
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/AbstractSocketEvent.java66
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/AbstractSocketWrapper.java200
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketClosedEvent.java17
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketConnectedEvent.java21
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketCreatedEvent.java17
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketEventCreateUtil.java60
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketEventSource.java47
11 files changed, 476 insertions, 11 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/.classpath b/providers/bundles/org.eclipse.ecf.provider.filetransfer/.classpath
index ce0c7a5d4..6f3b481ac 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/.classpath
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.0%Foundation-1.0"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/.settings/org.eclipse.jdt.core.prefs b/providers/bundles/org.eclipse.ecf.provider.filetransfer/.settings/org.eclipse.jdt.core.prefs
index b0782b8a0..e9ecb61b5 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/.settings/org.eclipse.jdt.core.prefs
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Tue Feb 03 17:28:26 PST 2009
+#Wed Feb 18 10:08:46 PST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
@@ -24,7 +24,7 @@ org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
-org.eclipse.jdt.core.compiler.problem.discouragedReference=error
+org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
@@ -78,7 +78,6 @@ org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
-org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
@@ -165,7 +164,6 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
org.eclipse.jdt.core.formatter.indentation.size=4
-org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF
index de8a7fd07..e2e11140d 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF
@@ -11,10 +11,11 @@ Require-Bundle: org.eclipse.equinox.common,
org.eclipse.ecf.filetransfer,
org.eclipse.equinox.registry
Eclipse-LazyStart: true
-Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,
- J2SE-1.3
+Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
+ J2SE-1.4
Import-Package: org.eclipse.core.net.proxy;resolution:=optional,
org.eclipse.core.runtime.jobs,
+ org.eclipse.ecf.provider.filetransfer.events.socket;version="[1.0.0,2.0.0)",
org.eclipse.osgi.util;version="1.0.0",
org.osgi.framework;version="1.3.0",
org.osgi.service.log;version="1.3.0",
@@ -23,6 +24,7 @@ Import-Package: org.eclipse.core.net.proxy;resolution:=optional,
Bundle-ClassPath: .
Export-Package: org.eclipse.ecf.internal.provider.filetransfer;x-internal:=true,
org.eclipse.ecf.provider.filetransfer.browse,
+ org.eclipse.ecf.provider.filetransfer.events.socket;version="1.0";x-friends:="org.eclipse.ecf.provider.filetransfer.httpclient",
org.eclipse.ecf.provider.filetransfer.identity;x-internal:=false,
org.eclipse.ecf.provider.filetransfer.outgoing,
org.eclipse.ecf.provider.filetransfer.retrieve;x-internal:=false,
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java
index 9ee3d8e98..748f18a65 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java
@@ -35,7 +35,7 @@ public abstract class AbstractFileSystemBrowser {
protected IFileID fileID = null;
protected IRemoteFileSystemListener listener = null;
- protected Exception exception = null;
+ private Exception exception = null;
protected IRemoteFile[] remoteFiles = null;
protected Proxy proxy;
@@ -58,10 +58,10 @@ public abstract class AbstractFileSystemBrowser {
protected IStatus run(IProgressMonitor monitor) {
try {
if (monitor.isCanceled())
- throw new UserCancelledException(Messages.AbstractRetrieveFileTransfer_Exception_User_Cancelled);
+ throw newUserCancelledException();
runRequest();
} catch (Exception e) {
- AbstractFileSystemBrowser.this.exception = e;
+ AbstractFileSystemBrowser.this.setException(e);
} finally {
listener.handleRemoteFileEvent(createRemoteFileEvent());
cleanUp();
@@ -77,6 +77,19 @@ public abstract class AbstractFileSystemBrowser {
return request;
}
+ protected void canceling() {
+ request.cancel();
+ }
+
+ }
+
+ protected void cancel() {
+ synchronized (lock) {
+ if (job != null) {
+ job.cancel();
+ }
+ }
+
}
protected void cleanUp() {
@@ -238,4 +251,28 @@ public abstract class AbstractFileSystemBrowser {
setupProxy(proxy);
}
+ protected synchronized void setException(Exception exception) {
+ this.exception = exception;
+ }
+
+ protected synchronized Exception getException() {
+ return this.exception;
+ }
+
+ protected synchronized boolean isCanceled() {
+ return exception instanceof UserCancelledException;
+ }
+
+ protected synchronized void setCanceled(Exception e) {
+ if (e instanceof UserCancelledException) {
+ exception = e;
+ } else {
+ exception = newUserCancelledException();
+ }
+ }
+
+ protected UserCancelledException newUserCancelledException() {
+ return new UserCancelledException(Messages.AbstractRetrieveFileTransfer_Exception_User_Cancelled);
+ }
+
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/AbstractSocketEvent.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/AbstractSocketEvent.java
new file mode 100644
index 000000000..77bd5c73a
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/AbstractSocketEvent.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+* Copyright (c) 2009 IBM, and others.
+* 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:
+* IBM Corporation - initial API and implementation
+******************************************************************************/
+
+package org.eclipse.ecf.provider.filetransfer.events.socket;
+
+import java.net.Socket;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.filetransfer.events.socket.ISocketEvent;
+import org.eclipse.ecf.filetransfer.events.socket.ISocketEventSource;
+
+public abstract class AbstractSocketEvent implements ISocketEvent {
+ private Socket factorySocket;
+ private Socket wrappedSocket;
+ private ISocketEventSource source;
+
+ protected AbstractSocketEvent(ISocketEventSource source, Socket factorySocket, Socket wrappedSocket) {
+ Assert.isNotNull(source);
+ Assert.isNotNull(factorySocket);
+ Assert.isNotNull(wrappedSocket);
+ this.source = source;
+ this.factorySocket = factorySocket;
+ this.wrappedSocket = wrappedSocket;
+ }
+
+ public ISocketEventSource getSource() {
+ return source;
+ }
+
+ public Socket getFactorySocket() {
+ return factorySocket;
+ }
+
+ public boolean isSameFactorySocket(ISocketEvent event) {
+ AbstractSocketEvent other = (AbstractSocketEvent) event;
+ return this.getFactorySocket() == other.getFactorySocket();
+ }
+
+ public Socket getSocket() {
+ return wrappedSocket;
+ }
+
+ protected void setSocket(Socket socket) {
+ this.wrappedSocket = socket;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer(getEventName() + "["); //$NON-NLS-1$
+ sb.append("source="); //$NON-NLS-1$
+ sb.append(source);
+ sb.append(" socket="); //$NON-NLS-1$
+ sb.append(getSocket());
+ sb.append(']');
+ return sb.toString();
+ }
+
+ protected abstract String getEventName();
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/AbstractSocketWrapper.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/AbstractSocketWrapper.java
new file mode 100644
index 000000000..62a7056a1
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/AbstractSocketWrapper.java
@@ -0,0 +1,200 @@
+package org.eclipse.ecf.provider.filetransfer.events.socket;
+
+import java.io.*;
+import java.net.*;
+import org.eclipse.core.runtime.Assert;
+
+public abstract class AbstractSocketWrapper extends Socket {
+
+ private Socket socket;
+
+ /**
+ * @throws IOException
+ */
+ protected void checkCancel() throws IOException {
+ // default does not check for cancel
+ }
+
+ public Socket getSocket() {
+ return socket;
+ }
+
+ /**
+ * @param socket
+ */
+ public AbstractSocketWrapper(Socket socket) {
+ super();
+ Assert.isNotNull(socket);
+ this.socket = socket;
+ }
+
+ public void bind(SocketAddress bindpoint) throws IOException {
+ checkCancel();
+ socket.bind(bindpoint);
+ }
+
+ public void close() throws IOException {
+ socket.close();
+ }
+
+ public void connect(SocketAddress endpoint, int timeout) throws IOException {
+ checkCancel();
+ socket.connect(endpoint, timeout);
+ }
+
+ public void connect(SocketAddress endpoint) throws IOException {
+ checkCancel();
+ socket.connect(endpoint);
+ }
+
+ public boolean equals(Object obj) {
+ return socket.equals(obj);
+ }
+
+ public InetAddress getInetAddress() {
+ return socket.getInetAddress();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ checkCancel();
+ return socket.getInputStream();
+ }
+
+ public boolean getKeepAlive() throws SocketException {
+ return socket.getKeepAlive();
+ }
+
+ public InetAddress getLocalAddress() {
+ return socket.getLocalAddress();
+ }
+
+ public int getLocalPort() {
+ return socket.getLocalPort();
+ }
+
+ public SocketAddress getLocalSocketAddress() {
+ return socket.getLocalSocketAddress();
+ }
+
+ public boolean getOOBInline() throws SocketException {
+ return socket.getOOBInline();
+ }
+
+ public OutputStream getOutputStream() throws IOException {
+ checkCancel();
+ return socket.getOutputStream();
+ }
+
+ public int getPort() {
+ return socket.getPort();
+ }
+
+ public int getReceiveBufferSize() throws SocketException {
+ return socket.getReceiveBufferSize();
+ }
+
+ public SocketAddress getRemoteSocketAddress() {
+ return socket.getRemoteSocketAddress();
+ }
+
+ public boolean getReuseAddress() throws SocketException {
+ return socket.getReuseAddress();
+ }
+
+ public int getSendBufferSize() throws SocketException {
+ return socket.getSendBufferSize();
+ }
+
+ public int getSoLinger() throws SocketException {
+ return socket.getSoLinger();
+ }
+
+ public int getSoTimeout() throws SocketException {
+ return socket.getSoTimeout();
+ }
+
+ public boolean getTcpNoDelay() throws SocketException {
+ return socket.getTcpNoDelay();
+ }
+
+ public int getTrafficClass() throws SocketException {
+ return socket.getTrafficClass();
+ }
+
+ public int hashCode() {
+ return socket.hashCode();
+ }
+
+ public boolean isBound() {
+ return socket.isBound();
+ }
+
+ public boolean isClosed() {
+ return socket.isClosed();
+ }
+
+ public boolean isConnected() {
+ return socket.isConnected();
+ }
+
+ public boolean isInputShutdown() {
+ return socket.isInputShutdown();
+ }
+
+ public boolean isOutputShutdown() {
+ return socket.isOutputShutdown();
+ }
+
+ public void sendUrgentData(int data) throws IOException {
+ checkCancel();
+ socket.sendUrgentData(data);
+ }
+
+ public void setKeepAlive(boolean on) throws SocketException {
+ socket.setKeepAlive(on);
+ }
+
+ public void setOOBInline(boolean on) throws SocketException {
+ socket.setOOBInline(on);
+ }
+
+ public void setReceiveBufferSize(int size) throws SocketException {
+ socket.setReceiveBufferSize(size);
+ }
+
+ public void setReuseAddress(boolean on) throws SocketException {
+ socket.setReuseAddress(on);
+ }
+
+ public void setSendBufferSize(int size) throws SocketException {
+ socket.setSendBufferSize(size);
+ }
+
+ public void setSoLinger(boolean on, int linger) throws SocketException {
+ socket.setSoLinger(on, linger);
+ }
+
+ public void setSoTimeout(int timeout) throws SocketException {
+ socket.setSoTimeout(timeout);
+ }
+
+ public void setTcpNoDelay(boolean on) throws SocketException {
+ socket.setTcpNoDelay(on);
+ }
+
+ public void setTrafficClass(int tc) throws SocketException {
+ socket.setTrafficClass(tc);
+ }
+
+ public void shutdownInput() throws IOException {
+ socket.shutdownInput();
+ }
+
+ public void shutdownOutput() throws IOException {
+ socket.shutdownOutput();
+ }
+
+ public String toString() {
+ return socket.toString();
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketClosedEvent.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketClosedEvent.java
new file mode 100644
index 000000000..527d48442
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketClosedEvent.java
@@ -0,0 +1,17 @@
+package org.eclipse.ecf.provider.filetransfer.events.socket;
+
+import java.net.Socket;
+import org.eclipse.ecf.filetransfer.events.socket.ISocketClosedEvent;
+import org.eclipse.ecf.filetransfer.events.socket.ISocketEventSource;
+
+public class SocketClosedEvent extends AbstractSocketEvent implements ISocketClosedEvent {
+
+ public SocketClosedEvent(ISocketEventSource source, Socket factorySocket, Socket wrappedSocket) {
+ super(source, factorySocket, wrappedSocket);
+ }
+
+ protected String getEventName() {
+ return "SocketClosedEvent"; //$NON-NLS-1$
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketConnectedEvent.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketConnectedEvent.java
new file mode 100644
index 000000000..ea417526f
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketConnectedEvent.java
@@ -0,0 +1,21 @@
+package org.eclipse.ecf.provider.filetransfer.events.socket;
+
+import java.net.Socket;
+import org.eclipse.ecf.filetransfer.events.socket.ISocketConnectedEvent;
+import org.eclipse.ecf.filetransfer.events.socket.ISocketEventSource;
+
+public class SocketConnectedEvent extends AbstractSocketEvent implements ISocketConnectedEvent {
+
+ public SocketConnectedEvent(ISocketEventSource source, Socket factorySocket, Socket wrappedSocket) {
+ super(source, factorySocket, wrappedSocket);
+ }
+
+ protected String getEventName() {
+ return "SocketConnectedEvent"; //$NON-NLS-1$
+ }
+
+ public void setSocket(Socket socket) {
+ super.setSocket(socket);
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketCreatedEvent.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketCreatedEvent.java
new file mode 100644
index 000000000..2a711767e
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketCreatedEvent.java
@@ -0,0 +1,17 @@
+package org.eclipse.ecf.provider.filetransfer.events.socket;
+
+import java.net.Socket;
+import org.eclipse.ecf.filetransfer.events.socket.ISocketCreatedEvent;
+import org.eclipse.ecf.filetransfer.events.socket.ISocketEventSource;
+
+public class SocketCreatedEvent extends AbstractSocketEvent implements ISocketCreatedEvent {
+
+ public SocketCreatedEvent(ISocketEventSource source, Socket socket) {
+ super(source, socket, socket);
+ }
+
+ protected String getEventName() {
+ return "SocketCreatedEvent"; //$NON-NLS-1$
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketEventCreateUtil.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketEventCreateUtil.java
new file mode 100644
index 000000000..d2f18d019
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketEventCreateUtil.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+* Copyright (c) 2009 IBM, and others.
+* 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:
+* IBM Corporation - initial API and implementation
+******************************************************************************/
+
+package org.eclipse.ecf.provider.filetransfer.events.socket;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import org.eclipse.ecf.filetransfer.events.socket.*;
+import org.eclipse.ecf.filetransfer.events.socketfactory.INonconnectedSocketFactory;
+
+public class SocketEventCreateUtil {
+
+ static void fireEvent(final ISocketListener spyListener, ISocketEvent event) {
+ if (spyListener != null) {
+ spyListener.handleSocketEvent(event);
+ }
+ event.getSource().fireEvent(event);
+ }
+
+ public static Socket createSocket(final ISocketListener spyListener, final ISocketEventSource socketEventSource, final INonconnectedSocketFactory unconnectedFactory, final InetSocketAddress remoteInetAddress, final InetSocketAddress localInetAddress, int timeout) throws IOException {
+ final Socket factorySocket = unconnectedFactory.createSocket();
+ fireEvent(spyListener, new SocketCreatedEvent(socketEventSource, factorySocket));
+ try {
+ factorySocket.bind(localInetAddress);
+ factorySocket.connect(remoteInetAddress, timeout);
+ } catch (IOException e) {
+ fireEvent(spyListener, new SocketClosedEvent(socketEventSource, factorySocket, factorySocket));
+ throw e;
+ }
+ final Socket[] wrap = new Socket[1];
+ final Socket myWrap = new AbstractSocketWrapper(factorySocket) {
+ public void close() throws IOException {
+ try {
+ super.close();
+ } finally {
+ fireEvent(spyListener, new SocketClosedEvent(socketEventSource, factorySocket, wrap[0]));
+ }
+ }
+ };
+ SocketConnectedEvent connectedEvent = new SocketConnectedEvent(socketEventSource, factorySocket, myWrap);
+ fireEvent(spyListener, connectedEvent);
+ if (connectedEvent.getSocket() == myWrap) {
+ wrap[0] = myWrap;
+ } else {
+ wrap[0] = connectedEvent.getSocket();
+ }
+
+ return wrap[0];
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketEventSource.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketEventSource.java
new file mode 100644
index 000000000..0e132f002
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/events/socket/SocketEventSource.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+* Copyright (c) 2009 IBM, and others.
+* 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:
+* IBM Corporation - initial API and implementation
+******************************************************************************/
+
+package org.eclipse.ecf.provider.filetransfer.events.socket;
+
+import java.util.*;
+import org.eclipse.ecf.filetransfer.events.socket.*;
+
+public abstract class SocketEventSource implements ISocketEventSource {
+
+ private final List listeners = new ArrayList();
+
+ public void addListener(ISocketListener l) {
+ synchronized (listeners) {
+ listeners.add(l);
+ }
+ }
+
+ public void removeListener(ISocketListener l) {
+ synchronized (listeners) {
+ listeners.remove(l);
+ }
+ }
+
+ public void fireEvent(ISocketEvent event) {
+ List toNotify = null;
+ // Copy array
+ synchronized (listeners) {
+ toNotify = new ArrayList(listeners);
+ }
+ // Notify all in toNotify
+ for (Iterator i = toNotify.iterator(); i.hasNext();) {
+ ISocketListener l = (ISocketListener) i.next();
+ l.handleSocketEvent(event);
+ }
+
+ }
+
+}

Back to the top