Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EDCD417E37 for ; Fri, 22 May 2015 07:07:53 +0000 (UTC) Received: (qmail 32036 invoked by uid 500); 22 May 2015 07:07:53 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 32000 invoked by uid 500); 22 May 2015 07:07:53 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 31985 invoked by uid 99); 22 May 2015 07:07:53 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 May 2015 07:07:53 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 6B230181A27 for ; Fri, 22 May 2015 07:07:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id CU03gRwwIxyy for ; Fri, 22 May 2015 07:07:48 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 8AC2E47BCF for ; Fri, 22 May 2015 07:07:47 +0000 (UTC) Received: (qmail 31666 invoked by uid 99); 22 May 2015 07:07:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 May 2015 07:07:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 10D7BE4412; Fri, 22 May 2015 07:07:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anovikov@apache.org To: commits@ignite.incubator.apache.org Date: Fri, 22 May 2015 07:08:02 -0000 Message-Id: In-Reply-To: <18507b6cf929426e8bce640e46f40d21@git.apache.org> References: <18507b6cf929426e8bce640e46f40d21@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [17/32] incubator-ignite git commit: # IGNITE-915: Implemented. # IGNITE-915: Implemented. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/c3dde572 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/c3dde572 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/c3dde572 Branch: refs/heads/ignite-843 Commit: c3dde5726a84645d6d08b69099c644d250d0dbcb Parents: 2149639 Author: vozerov-gridgain Authored: Mon May 18 11:27:44 2015 +0300 Committer: vozerov-gridgain Committed: Mon May 18 11:27:44 2015 +0300 ---------------------------------------------------------------------- .../internal/interop/InteropIgnition.java | 65 +++++++++++++++++++- .../internal/interop/InteropProcessor.java | 13 +++- 2 files changed, 76 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3dde572/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java index f245122..3ccd361 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropIgnition.java @@ -25,6 +25,7 @@ import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.jetbrains.annotations.*; +import java.lang.ref.*; import java.net.*; import java.security.*; import java.util.*; @@ -52,9 +53,19 @@ public class InteropIgnition { InteropBootstrap bootstrap = bootstrap(factoryId); - return bootstrap.start(cfg, envPtr); + InteropProcessor proc = bootstrap.start(cfg, envPtr); + + trackFinalization(proc); + + return proc; } + /** + * Create configuration. + * + * @param springCfgPath Path to Spring XML. + * @return Configuration. + */ private static IgniteConfiguration configuration(@Nullable String springCfgPath) { try { URL url = springCfgPath == null ? U.resolveIgniteUrl(IgnitionEx.DFLT_CFG) : @@ -95,6 +106,58 @@ public class InteropIgnition { } /** + * Track processor finalization. + * + * @param proc Processor. + */ + private static void trackFinalization(InteropProcessor proc) { + Thread thread = new Thread(new Finalizer(proc)); + + thread.setDaemon(true); + + thread.start(); + } + + /** + * Finalizer runnable. + */ + private static class Finalizer implements Runnable { + /** Queue where we expect notification to appear. */ + private final ReferenceQueue queue; + + /** Phantom reference to processor. */ + private final PhantomReference proc; + + /** Cleanup runnable. */ + private final Runnable cleanup; + + /** + * Constructor. + * + * @param proc Processor. + */ + public Finalizer(InteropProcessor proc) { + queue = new ReferenceQueue<>(); + + this.proc = new PhantomReference<>(proc, queue); + + cleanup = proc.cleanupCallback(); + } + + /** {@inheritDoc} */ + @Override public void run() { + try { + queue.remove(0); + + cleanup.run(); + } + catch (InterruptedException ignore) { + // No-op. + } + } + } + + /** * Private constructor. */ private InteropIgnition() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c3dde572/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java index 6c55296..aa4f877 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/interop/InteropProcessor.java @@ -17,9 +17,20 @@ package org.apache.ignite.internal.interop; +import org.jetbrains.annotations.*; + /** * Interop processor. */ public interface InteropProcessor { - // No-op. + /** + * Get stop runnable to perform cleanup when interop is not longer used. + *

+ * NOTE! This runnable is called when current instance of interop processor is eligible for garbage + * collection. Therefore you should never store any references to Ignite internal inside it. Otherwise + * this runnable will never be called. + * + * @return Stop runnable. If {@code null} is returned, then no cleanup is expected. + */ + @Nullable public Runnable cleanupCallback(); }