Return-Path: X-Original-To: apmail-ignite-dev-archive@minotaur.apache.org Delivered-To: apmail-ignite-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 80E7318099 for ; Tue, 29 Mar 2016 22:50:05 +0000 (UTC) Received: (qmail 47554 invoked by uid 500); 29 Mar 2016 22:50:05 -0000 Delivered-To: apmail-ignite-dev-archive@ignite.apache.org Received: (qmail 47516 invoked by uid 500); 29 Mar 2016 22:50:05 -0000 Mailing-List: contact dev-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list dev@ignite.apache.org Received: (qmail 47498 invoked by uid 99); 29 Mar 2016 22:50:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Mar 2016 22:50:04 +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 93E7C18028D for ; Tue, 29 Mar 2016 22:50:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.198 X-Spam-Level: * X-Spam-Status: No, score=1.198 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 6DarqdAalhNV for ; Tue, 29 Mar 2016 22:50:02 +0000 (UTC) Received: from mail-qg0-f46.google.com (mail-qg0-f46.google.com [209.85.192.46]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 97C505F1D5 for ; Tue, 29 Mar 2016 22:50:01 +0000 (UTC) Received: by mail-qg0-f46.google.com with SMTP id j35so25244162qge.0 for ; Tue, 29 Mar 2016 15:50:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=UODA6Zq1w1SDoj8pldmA+QEFYaM7xTl65IOdQizq8Z8=; b=toEYdw2PBDlil0QMKQ6V30fh6Lw4pA/8ucHK1nYwR9bgirjEOSH+Y5WrhBkyY9OFXp x0HrUByZfmDEvzcETOfrz1z8WLnVy/MbyDfo76Kwa27z3rYdw+NDWP9IGd8M9WOO71as J/6cfUo9x4xs8GNqdIw+MvwQth6xg4a7OtgBquCmA0zP1RuT/CSlK4Joh++0l/ytSrRo m61mPUMF44g/Rj/Ykp7dv6yELTUpwiZzE5RZq6LDoJ960Fm438rI9JwUOApkyyTEE5o4 zQiTlV8qQnEIy4cgZajy7q5nHCZBAAKzveSKnUl34y5FiIoJky9Nwf1f8WBdIvwWrUUP ishQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=UODA6Zq1w1SDoj8pldmA+QEFYaM7xTl65IOdQizq8Z8=; b=XEb9sfkzahO+IjDKutnLGGeGXWJJdd2XIWXAjPPHqPhZjkfVwAB26KSAiqKJkGMFQ+ 0EtQyhqP0OFSBgpreON11N1zdlBp2Ri74IjN3hA9EmZ6/wVSziM4+d2uTnikqc8gCcbI 5C/pfsWo4FAXZjmUjDLGanm5y2tNonplfIvGiXRl1pBKSfqQYajbPcrXnqtv6fLhrBy6 pRHNEATZi4Q5qAWKKGn/KNoYVNCjOf+e4KZ8koDZrs86VT+oOO7+p2k380HIdmh2Md4d iLFQecQ0gkgMo3qfwjw/sDVV8dsTnJpPvxNNpHvQA8CjjZY/4DdroAAbnAzX99qNH+KT UJcA== X-Gm-Message-State: AD7BkJLQFECBDsiJUztzXmon36AX+tJXcZ2i9zcc3pp7i0SRel/8ofDWqNzOKdLvR4IO8HYsRXYKPZ9c+GaopA== X-Received: by 10.140.22.139 with SMTP id 11mr6157765qgn.34.1459291795189; Tue, 29 Mar 2016 15:49:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.29.180 with HTTP; Tue, 29 Mar 2016 15:49:25 -0700 (PDT) In-Reply-To: <56FA434B.5050201@gridgain.com> References: <56FA434B.5050201@gridgain.com> From: Valentin Kulichenko Date: Tue, 29 Mar 2016 15:49:25 -0700 Message-ID: Subject: Re: Controlling type of object inserted in IgniteCache To: dev@ignite.apache.org Content-Type: multipart/alternative; boundary=001a11c151e213761b052f37d92a --001a11c151e213761b052f37d92a Content-Type: text/plain; charset=UTF-8 How about adding setTypeNames() configuration property that will be similar to setTypes(), but for binary objects? -Val On Tue, Mar 29, 2016 at 1:56 AM, Denis Magda wrote: > Igniters, > > In some cases there is necessity to control a type of object that is being > inserted into a cache. > Presently this kind of check is accomplished at compile time only relying > on Java Generics. However it doesn't prevent us from connecting to a > cluster using a non-generic instance of a cache and put any kind of data in > it. > This may be not a harmful intention but rather a silly developer mistake. > > I see the following options here. > > 1) First CacheInterceptor based approach. > Specify a unique interceptor per cache setting expected typeName/typeId to > it at construction time and the interceptor will validate object type in > onBeforePut() method. > Disadvantages: > - cache interceptor have to be created for every cache; > - cache interceptor class has to be located in servers classpath. It means > that we won't be able to start a new cache with its interceptor later. > > 2) Second CacheInterceptor based approach. > A generic cache interceptor can be created. It will be populated with a > map of cacheName->typeName values at initialization time and validation may > look like below > > @CacheNameResource String cacheName; > > public Object onBeforePut(Cache.Entry > entry,BinaryObject newVal) { > if (typeId ==null) { > synchronized (cachesTypes) { > if (typeId ==null) { > String allowedType =cachesTypes.get(cacheName); > > if (allowedType ==null) { > typeId =0; > > throw new IgniteException("No type for cache name:" > +cacheName); > } > > typeId = Ignition.ignite().binary().typeId(allowedType); > } > } > } > > if (newVal.type().typeId() !=typeId) > throw new IgniteException("Invalid object type [validType=" > +typeId +", wrongType=" + newVal.type().typeId()); > > return newVal; > } > > However if we want to start a new cache then we won't be able to add a new > entry to "cacheTypes" map. 3) MutableConfiguration.setTypes(Class > keyType, Class valueType) based approach According to the spec > > Implementations may further perform type checking on mutative cache > operations * and throw a {@link ClassCastException} if these checks fail. > > If we see that value type is BinaryObject (this can be a case if there > BinaryObject is not going to be deserialized because no real class exists > for it) then we can take its typeName/typeId and compare it with the same > parameters at the time instances of BinaryObjects will be put to cache > using cache.put(). So, every time cache.put()/putAll() are called we can > check type on client nodes before sending values to servers. In case of > CacheEntryProcessors servers will double-check an entry type after the > entry processor does its job. I prefer the latest approach. Any thoughts on > this? -- Denis > --001a11c151e213761b052f37d92a--