summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-02-25 02:46:33 (EST)
committerEike Stepper2007-02-25 02:46:33 (EST)
commit746bdeef16b3359802eaf19a660781a0d5256414 (patch)
tree10339da8e531549210b1759b9062e1889ff964e5
parent1396f2c897936175090e273e112f5f24293a602f (diff)
downloadcdo-746bdeef16b3359802eaf19a660781a0d5256414.zip
cdo-746bdeef16b3359802eaf19a660781a0d5256414.tar.gz
cdo-746bdeef16b3359802eaf19a660781a0d5256414.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java7
-rw-r--r--plugins/org.eclipse.net4j/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyBundle.java5
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiBundle.java8
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractAcceptor.java1
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMBundle.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/FileStore.java55
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/Store.java200
8 files changed, 278 insertions, 1 deletions
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java
index 86930f6..cc48fbe 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java
@@ -36,6 +36,8 @@ public class TCPAcceptorImpl extends AbstractAcceptor implements TCPAcceptor, TC
{
private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_ACCEPTOR, TCPAcceptorImpl.class);
+ private static final String DEFAULT_ADDRESS = "0.0.0.0";
+
private TCPSelector selector;
private ServerSocketChannel serverSocketChannel;
@@ -132,6 +134,11 @@ public class TCPAcceptorImpl extends AbstractAcceptor implements TCPAcceptor, TC
{
String[] elements = DescriptionUtil.getElements(getDescription());
address = elements[1];
+ if (address.length() == 0)
+ {
+ address = DEFAULT_ADDRESS;
+ }
+
port = Integer.parseInt(elements[2]);
}
diff --git a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
index 7c2876e..ddce4d2 100644
--- a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
@@ -32,6 +32,7 @@ Export-Package: org.eclipse.internal.net4j.bundle;version="0.8.0",
org.eclipse.net4j.util.om.log;version="0.8.0",
org.eclipse.net4j.util.om.trace;version="0.8.0",
org.eclipse.net4j.util.registry;version="0.8.0",
+ org.eclipse.net4j.util.store;version="0.8.0",
org.eclipse.net4j.util.stream;version="0.8.0"
Eclipse-LazyStart: true
Require-Bundle: org.eclipse.core.runtime;resolution:=optional
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyBundle.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyBundle.java
index 0b66258..8728da5 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyBundle.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/LegacyBundle.java
@@ -44,6 +44,11 @@ public class LegacyBundle extends AbstractOMBundle
}
}
+ public String getStateLocation()
+ {
+ throw new UnsupportedOperationException();
+ }
+
public URL getBaseURL()
{
return baseURL;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiBundle.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiBundle.java
index 47a4262..881430e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiBundle.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OSGiBundle.java
@@ -13,7 +13,9 @@ package org.eclipse.internal.net4j.bundle;
import org.eclipse.net4j.util.IOUtil;
import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import java.io.IOException;
@@ -48,4 +50,10 @@ public class OSGiBundle extends AbstractOMBundle
return null;
}
}
+
+ public String getStateLocation()
+ {
+ Bundle bundle = getBundleContext().getBundle();
+ return Platform.getStateLocation(bundle).toString();
+ }
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractAcceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractAcceptor.java
index 960292b..97bd006 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractAcceptor.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractAcceptor.java
@@ -39,7 +39,6 @@ import java.util.concurrent.ExecutorService;
* @author Eike Stepper
*/
public abstract class AbstractAcceptor extends LifecycleImpl implements Acceptor, INotifier.Introspection
-
{
private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_ACCEPTOR, AbstractAcceptor.class);
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMBundle.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMBundle.java
index f566605..89c5706 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMBundle.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMBundle.java
@@ -49,6 +49,8 @@ public interface OMBundle
public void setDebugOption(String option, int value);
+ public String getStateLocation();
+
public InputStream getInputStream(String path) throws IOException;
/**
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/FileStore.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/FileStore.java
new file mode 100644
index 0000000..f645869
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/FileStore.java
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * Copyright (c) 2004-2007 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.util.store;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class FileStore<CONTENT> extends Store<CONTENT>
+{
+ private File file;
+
+ public FileStore(File file)
+ {
+ this.file = file;
+ }
+
+ public File getFile()
+ {
+ return file;
+ }
+
+ @Override
+ protected InputStream getInputStream() throws IOException
+ {
+ return new FileInputStream(file);
+ }
+
+ @Override
+ protected OutputStream getOutputStream() throws IOException
+ {
+ return new FileOutputStream(file);
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("FileStore[{0}]", file.getAbsolutePath());
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/Store.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/Store.java
new file mode 100644
index 0000000..bd68649
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/store/Store.java
@@ -0,0 +1,200 @@
+/***************************************************************************
+ * Copyright (c) 2004-2007 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.util.store;
+
+import org.eclipse.net4j.util.IOUtil;
+import org.eclipse.net4j.util.lifecycle.LifecycleImpl;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.Net4j;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Store<CONTENT> extends LifecycleImpl
+{
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG, Store.class);
+
+ private CONTENT content;
+
+ private boolean dirty;
+
+ public Store()
+ {
+ }
+
+ public CONTENT getContent()
+ {
+ return content;
+ }
+
+ public boolean isDirty()
+ {
+ return dirty;
+ }
+
+ public void setDirty()
+ {
+ dirty = true;
+ }
+
+ @Override
+ protected void onActivate() throws Exception
+ {
+ super.onActivate();
+ loadContent();
+ }
+
+ @Override
+ protected void onDeactivate() throws Exception
+ {
+ if (dirty)
+ {
+ saveContent();
+ dirty = false;
+ }
+
+ super.onDeactivate();
+ }
+
+ private void loadContent() throws Exception
+ {
+ ObjectInputStream ois = null;
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Loading content");
+ }
+
+ try
+ {
+ ois = new StoreInputStream(getInputStream());
+ content = (CONTENT)ois.readObject();
+ }
+ catch (Exception ex)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Initializing content");
+ }
+
+ content = getInitialContent();
+
+ if (!(ex instanceof FileNotFoundException))
+ {
+ throw ex;
+ }
+ }
+ finally
+ {
+ IOUtil.closeSilent(ois);
+ }
+ }
+
+ private void saveContent()
+ {
+ ObjectOutputStream oos = null;
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Saving content");
+ }
+
+ try
+ {
+ oos = new StoreOutputStream(getOutputStream());
+ oos.writeObject(content);
+ }
+ catch (Exception ex)
+ {
+ Net4j.LOG.error(ex);
+ }
+ finally
+ {
+ IOUtil.closeSilent(oos);
+ }
+ }
+
+ protected String formatForTracing(Object obj)
+ {
+ if (obj instanceof String)
+ {
+ return (String)obj;
+ }
+
+ return null;
+ }
+
+ protected abstract CONTENT getInitialContent();
+
+ protected abstract InputStream getInputStream() throws IOException;
+
+ protected abstract OutputStream getOutputStream() throws IOException;
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class StoreInputStream extends ObjectInputStream
+ {
+ private StoreInputStream(InputStream in) throws IOException
+ {
+ super(in);
+ enableResolveObject(true);
+ }
+
+ @Override
+ protected Object resolveObject(Object obj) throws IOException
+ {
+ if (TRACER.isEnabled() && obj instanceof String)
+ {
+ String str = formatForTracing(obj);
+ if (str != null)
+ {
+ TRACER.trace("Loaded " + obj);
+ }
+ }
+
+ return super.resolveObject(obj);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class StoreOutputStream extends ObjectOutputStream
+ {
+ private StoreOutputStream(OutputStream out) throws IOException
+ {
+ super(out);
+ enableReplaceObject(true);
+ }
+
+ @Override
+ protected Object replaceObject(Object obj) throws IOException
+ {
+ if (TRACER.isEnabled())
+ {
+ String str = formatForTracing(obj);
+ if (str != null)
+ {
+ TRACER.trace("Saved " + obj);
+ }
+ }
+
+ return super.replaceObject(obj);
+ }
+ }
+} \ No newline at end of file