summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-10-24 05:50:14 (EDT)
committerEike Stepper2006-10-24 05:50:14 (EDT)
commit73ab230d762acbe084c562c88ee5b699e860958b (patch)
tree910c912fdb8f6cb5914a99e032f98116716aa8da
parent107521df821d72413751bd6c98ceb71a8a60334b (diff)
downloadcdo-73ab230d762acbe084c562c88ee5b699e860958b.zip
cdo-73ab230d762acbe084c562c88ee5b699e860958b.tar.gz
cdo-73ab230d762acbe084c562c88ee5b699e860958b.tar.bz2
Introduced new lifecycle phase AboutToActivate
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java19
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java24
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ClientTCPConnectorImpl.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java9
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/AbstractLifecycle.java27
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/LifecycleListener.java2
9 files changed, 78 insertions, 17 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
index 17572d5..446d233 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
@@ -74,7 +74,8 @@ public class TCPTransportTest extends TestCase
assertTrue(selector.isActive());
acceptor = (TCPAcceptorImpl)Net4jFactory.createTCPAcceptor(bufferPool, selector);
- connector = (AbstractTCPConnector)Net4jFactory.createTCPConnector(bufferPool, selector, "localhost");
+ connector = (AbstractTCPConnector)Net4jFactory.createTCPConnector(bufferPool, selector,
+ "localhost");
}
@Override
@@ -275,6 +276,10 @@ public class TCPTransportTest extends TestCase
{
connector.addChannelListener(new Connector.ChannelListener()
{
+ public void notifyChannelAboutToOpen(Channel channel)
+ {
+ }
+
public void notifyChannelClosing(Channel channel)
{
}
@@ -332,6 +337,10 @@ public class TCPTransportTest extends TestCase
{
connector.addChannelListener(new Connector.ChannelListener()
{
+ public void notifyChannelAboutToOpen(Channel channel)
+ {
+ }
+
public void notifyChannelClosing(Channel channel)
{
}
@@ -396,6 +405,10 @@ public class TCPTransportTest extends TestCase
{
connector.addChannelListener(new Connector.ChannelListener()
{
+ public void notifyChannelAboutToOpen(Channel channel)
+ {
+ }
+
public void notifyChannelClosing(Channel channel)
{
}
@@ -474,6 +487,10 @@ public class TCPTransportTest extends TestCase
{
connector.addChannelListener(new Connector.ChannelListener()
{
+ public void notifyChannelAboutToOpen(Channel channel)
+ {
+ }
+
public void notifyChannelClosing(Channel channel)
{
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java
index acaa90c..99fc973 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java
@@ -451,6 +451,20 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
return factory.createProtocol(channel);
}
+ protected void fireChannelAboutToOpen(Channel channel)
+ {
+ for (ChannelListener listener : channelListeners)
+ {
+ try
+ {
+ listener.notifyChannelOpened(channel);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
protected void fireChannelOpened(Channel channel)
{
for (ChannelListener listener : channelListeners)
@@ -497,9 +511,9 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
}
@Override
- protected void onAccessBeforeActivate() throws Exception
+ protected void onAboutToActivate() throws Exception
{
- super.onAccessBeforeActivate();
+ super.onAboutToActivate();
if (bufferProvider == null)
{
throw new IllegalStateException("bufferProvider == null");
@@ -551,6 +565,12 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
*/
private final class ChannelLifecycleListener implements LifecycleListener
{
+ public void notifyLifecycleAboutToActivate(LifecycleNotifier notifier)
+ {
+ ChannelImpl channel = (ChannelImpl)notifier;
+ fireChannelAboutToOpen(channel);
+ }
+
public void notifyLifecycleActivated(LifecycleNotifier notifier)
{
ChannelImpl channel = (ChannelImpl)notifier;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java
index 8924e2e..6547bab 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java
@@ -160,9 +160,9 @@ public class ChannelImpl extends AbstractLifecycle implements Channel, BufferPro
}
@Override
- protected void onAccessBeforeActivate() throws Exception
+ protected void onAboutToActivate() throws Exception
{
- super.onAccessBeforeActivate();
+ super.onAboutToActivate();
if (channelID == BufferImpl.NO_CHANNEL)
{
throw new IllegalStateException("channelID == INVALID_CHANNEL_ID");
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java
index 016fa43..3974062 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java
@@ -256,9 +256,9 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements
}
@Override
- protected void onAccessBeforeActivate() throws Exception
+ protected void onAboutToActivate() throws Exception
{
- super.onAccessBeforeActivate();
+ super.onAboutToActivate();
if (selector == null)
{
selector = Net4jFactory.createTCPSelector();
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ClientTCPConnectorImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ClientTCPConnectorImpl.java
index 769ab52..fd814b3 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ClientTCPConnectorImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ClientTCPConnectorImpl.java
@@ -59,9 +59,9 @@ public class ClientTCPConnectorImpl extends AbstractTCPConnector
}
@Override
- protected void onAccessBeforeActivate() throws Exception
+ protected void onAboutToActivate() throws Exception
{
- super.onAccessBeforeActivate();
+ super.onAboutToActivate();
if (host == null || host.length() == 0)
{
throw new IllegalArgumentException("host == null || host.length() == 0");
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
index 2a7e2bc..5ab5a44 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
@@ -178,6 +178,11 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
listeners.remove(listener);
}
+ public void notifyLifecycleAboutToActivate(LifecycleNotifier notifier)
+ {
+ // Do nothing
+ }
+
public void notifyLifecycleActivated(LifecycleNotifier notifier)
{
// Do nothing
@@ -276,9 +281,9 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
}
@Override
- protected void onAccessBeforeActivate() throws Exception
+ protected void onAboutToActivate() throws Exception
{
- super.onAccessBeforeActivate();
+ super.onAboutToActivate();
if (bufferProvider == null)
{
throw new IllegalStateException("bufferProvider == null");
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java
index 617047e..bea5c53 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java
@@ -150,6 +150,8 @@ public interface Connector
*/
public interface ChannelListener
{
+ public void notifyChannelAboutToOpen(Channel channel);
+
public void notifyChannelOpened(Channel channel);
public void notifyChannelClosing(Channel channel);
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/AbstractLifecycle.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/AbstractLifecycle.java
index 3e37b30..a7597d0 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/AbstractLifecycle.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/AbstractLifecycle.java
@@ -40,17 +40,18 @@ public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier
if (!active)
{
System.out.println(toString() + ": Activating");
- onAccessBeforeActivate();
- onActivate();
+ onAboutToActivate();
+ fireLifecycleAboutToActivate();
+
active = true;
+ onActivate();
+ fireLifecycleActivated();
if (DUMP_ON_ACTIVATE)
{
ReflectUtil.dump(this, toString() + ": DUMP ");
}
-
- fireLifecycleActivated();
- }
+}
}
public final synchronized Exception deactivate()
@@ -96,6 +97,20 @@ public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier
}
}
+ protected void fireLifecycleAboutToActivate()
+ {
+ for (LifecycleListener listener : listeners)
+ {
+ try
+ {
+ listener.notifyLifecycleAboutToActivate(this);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
protected void fireLifecycleActivated()
{
for (LifecycleListener listener : listeners)
@@ -126,7 +141,7 @@ public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier
}
}
- protected void onAccessBeforeActivate() throws Exception
+ protected void onAboutToActivate() throws Exception
{
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/LifecycleListener.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/LifecycleListener.java
index eaa3863..fc73590 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/LifecycleListener.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/LifecycleListener.java
@@ -5,6 +5,8 @@ package org.eclipse.net4j.util.lifecycle;
*/
public interface LifecycleListener
{
+ public void notifyLifecycleAboutToActivate(LifecycleNotifier notifier);
+
public void notifyLifecycleActivated(LifecycleNotifier notifier);
public void notifyLifecycleDeactivating(LifecycleNotifier notifier);