Repository: incubator-ignite Updated Branches: refs/heads/ignite-gg-9614 1077edcf8 -> 8deaf562a
# GG-9614 review: refactor remoteListen filter Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/8deaf562 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8deaf562 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8deaf562 Branch: refs/heads/ignite-gg-9614 Commit: 8deaf562a89dac602d1863816554f20fd180f980 Parents: 1077edc Author: ptupitsyn <[email protected]> Authored: Tue May 19 14:05:12 2015 +0300 Committer: ptupitsyn <[email protected]> Committed: Tue May 19 14:05:12 2015 +0300 ---------------------------------------------------------------------- .../internal/GridEventConsumeHandler.java | 3 +- .../internal/GridLifecycleAwareEventFilter.java | 35 ---------- .../ignite/internal/IgniteEventsImpl.java | 72 ++++---------------- .../interop/GridLifecycleAwareEventFilter.java | 37 ++++++++++ .../GridLifecycleAwareLocalEventListener.java | 28 ++++++++ .../eventstorage/GridEventStorageManager.java | 10 +-- .../GridLifecycleAwareLocalEventListener.java | 28 -------- 7 files changed, 81 insertions(+), 132 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8deaf562/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java index b02e66f..cf6d605 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java @@ -20,6 +20,7 @@ package org.apache.ignite.internal; import org.apache.ignite.*; import org.apache.ignite.cluster.*; import org.apache.ignite.events.*; +import org.apache.ignite.internal.interop.*; import org.apache.ignite.internal.managers.deployment.*; import org.apache.ignite.internal.managers.discovery.*; import org.apache.ignite.internal.managers.eventstorage.*; @@ -125,7 +126,7 @@ class GridEventConsumeHandler implements GridContinuousHandler { ctx.resource().injectGeneric(filter); if (filter instanceof GridLifecycleAwareEventFilter) - ((GridLifecycleAwareEventFilter)filter).initialize(); + ((GridLifecycleAwareEventFilter)filter).initialize(ctx.grid()); final boolean loc = nodeId.equals(ctx.localNodeId()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8deaf562/modules/core/src/main/java/org/apache/ignite/internal/GridLifecycleAwareEventFilter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridLifecycleAwareEventFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/GridLifecycleAwareEventFilter.java deleted file mode 100644 index 86a0e7a..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridLifecycleAwareEventFilter.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.apache.ignite.internal; - -import org.apache.ignite.lang.*; - -/** - * Special version of predicate for events with initialize/close callbacks. - */ -public interface GridLifecycleAwareEventFilter<E> extends IgnitePredicate<E> { - /** - * Initializes the filter. - */ - public void initialize(); - - /** - * Closes the filter. - */ - public void close(); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8deaf562/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java index b83b1fe..c27be6b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java @@ -24,7 +24,6 @@ import org.apache.ignite.internal.cluster.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; -import org.apache.ignite.resources.*; import org.jetbrains.annotations.*; import java.io.*; @@ -269,7 +268,18 @@ public class IgniteEventsImpl extends AsyncSupportAdapter<IgniteEvents> implemen */ private static <T extends Event> IgnitePredicate<T> compoundPredicate(final IgnitePredicate<T> p, @Nullable final int... types) { - return F.isEmpty(types) ? p : new IgniteCompoundPredicate<>(p, types); + + return F.isEmpty(types) ? p : + new IgnitePredicate<T>() { + @Override public boolean apply(T t) { + for (int type : types) { + if (type == t.type()) + return p.apply(t); + } + + return false; + } + }; } /** {@inheritDoc} */ @@ -296,62 +306,4 @@ public class IgniteEventsImpl extends AsyncSupportAdapter<IgniteEvents> implemen protected Object readResolve() throws ObjectStreamException { return prj.events(); } - - /** - * Compound predicate which adds type filtering - */ - private static class IgniteCompoundPredicate<T extends Event> implements IgnitePredicate<T>, - GridLifecycleAwareEventFilter<T> { - /** */ - private static final long serialVersionUID = 0L; - - /** Event types. */ - private final int[] types; - - /** Inner predicate. */ - private final IgnitePredicate<T> p; - - /** Grid. */ - @IgniteInstanceResource - private transient Ignite ignite; - - /** - * Constructor. - * @param p Predicate. - * @param types Event types. - */ - public IgniteCompoundPredicate(IgnitePredicate<T> p, final int... types) { - this.types = types; - this.p = p; - } - - /** {@inheritDoc} */ - @Override public boolean apply(T t) { - for (int type : types) { - if (type == t.type()) - return p.apply(t); - } - - return false; - } - - /** {@inheritDoc} */ - @Override public void initialize() { - try { - ((IgniteKernal)ignite).context().resource().injectGeneric(p); - } - catch (IgniteCheckedException e) { - throw new IgniteException("Failed to inject resources to event predicate: " + p, e); - } - - if (p instanceof GridLifecycleAwareEventFilter) - ((GridLifecycleAwareEventFilter)p).initialize(); - } - - /** {@inheritDoc} */ - @Override public void close() { - if (p instanceof GridLifecycleAwareEventFilter) - ((GridLifecycleAwareEventFilter)p).close(); - } - } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8deaf562/modules/core/src/main/java/org/apache/ignite/internal/interop/GridLifecycleAwareEventFilter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/GridLifecycleAwareEventFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/GridLifecycleAwareEventFilter.java new file mode 100644 index 0000000..13d6616 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/GridLifecycleAwareEventFilter.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.ignite.internal.interop; + +import org.apache.ignite.*; +import org.apache.ignite.events.*; +import org.apache.ignite.lang.*; + +/** + * Special version of predicate for events with initialize/close callbacks. + */ +public interface GridLifecycleAwareEventFilter<E extends Event> extends IgnitePredicate<E> { + /** + * Initializes the filter. + */ + public void initialize(Ignite ignite); + + /** + * Closes the filter. + */ + public void close(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8deaf562/modules/core/src/main/java/org/apache/ignite/internal/interop/GridLifecycleAwareLocalEventListener.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/GridLifecycleAwareLocalEventListener.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/GridLifecycleAwareLocalEventListener.java new file mode 100644 index 0000000..f5b363e --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/GridLifecycleAwareLocalEventListener.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.ignite.internal.interop; + +/** + * Special version of listener for events with close callbacks. + */ +public interface GridLifecycleAwareLocalEventListener { + /** + * Closes the listener. + */ + public void close(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8deaf562/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java index 0691b39..bd37b4f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java @@ -22,6 +22,7 @@ import org.apache.ignite.cluster.*; import org.apache.ignite.events.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.events.*; +import org.apache.ignite.internal.interop.*; import org.apache.ignite.internal.managers.*; import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.internal.managers.deployment.*; @@ -760,15 +761,8 @@ public class GridEventStorageManager extends GridManagerAdapter<EventStorageSpi> public <T extends Event> Collection<T> localEvents(IgnitePredicate<T> p) { assert p != null; - try { - ctx.resource().injectGeneric(p); - } - catch (IgniteCheckedException e) { - throw new IgniteException("Failed to inject resources to event predicate: " + p, e); - } - if (p instanceof GridLifecycleAwareEventFilter) - ((GridLifecycleAwareEventFilter)p).initialize(); + ((GridLifecycleAwareEventFilter)p).initialize(ctx.grid()); try { return getSpi().localEvents(p); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8deaf562/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridLifecycleAwareLocalEventListener.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridLifecycleAwareLocalEventListener.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridLifecycleAwareLocalEventListener.java deleted file mode 100644 index 31db6ac..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridLifecycleAwareLocalEventListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.apache.ignite.internal.managers.eventstorage; - -/** - * Special version of listener for events with close callbacks. - */ -public interface GridLifecycleAwareLocalEventListener { - /** - * Closes the listener. - */ - public void close(); -}
