Skip to content

Commit 4e34f58

Browse files
Pavel Tupitsynvozerov-gridgain
authored andcommitted
IGNITE-2979: .NET: Implemented ability to use Java filter in .NET-based continuous queries.
1 parent 18e355b commit 4e34f58

28 files changed

+2124
-7
lines changed

modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaFileUnlockProcessor;
8484
import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaUpdatePropertiesProcessor;
8585
import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaUpdateTimesProcessor;
86+
import org.apache.ignite.internal.processors.platform.PlatformJavaObjectFactoryProxy;
8687
import org.apache.ignite.internal.util.IgniteUtils;
8788
import org.apache.ignite.internal.util.lang.GridMapEntry;
8889
import org.apache.ignite.internal.util.typedef.F;
@@ -272,6 +273,8 @@ public BinaryContext(BinaryMetadataHandler metaHnd, IgniteConfiguration igniteCf
272273
registerPredefinedType(GridMapEntry.class, 60);
273274
registerPredefinedType(IgniteBiTuple.class, 61);
274275
registerPredefinedType(T2.class, 62);
276+
registerPredefinedType(PlatformJavaObjectFactoryProxy.class,
277+
GridBinaryMarshaller.PLATFORM_JAVA_OBJECT_FACTORY_PROXY);
275278

276279
registerPredefinedType(BinaryObjectImpl.class, 0);
277280
registerPredefinedType(BinaryObjectOffheapImpl.class, 0);

modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ public class GridBinaryMarshaller {
180180
/** */
181181
public static final byte LINKED_HASH_MAP = 2;
182182

183+
/** */
184+
public static final byte PLATFORM_JAVA_OBJECT_FACTORY_PROXY = 99;
185+
183186
/** */
184187
public static final int OBJECT_TYPE_ID = -1;
185188

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.processors.platform;
19+
20+
import org.apache.ignite.IgniteException;
21+
import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
22+
import org.apache.ignite.internal.util.typedef.internal.S;
23+
import org.jetbrains.annotations.Nullable;
24+
25+
import java.util.Map;
26+
27+
/**
28+
* Default Java object factory implementation.
29+
*/
30+
public class PlatformDefaultJavaObjectFactory<T> implements PlatformJavaObjectFactoryEx<T> {
31+
/** Class name. */
32+
private String clsName;
33+
34+
/** Properties. */
35+
private Map<String, Object> props;
36+
37+
/** {@inheritDoc} */
38+
@Override public void initialize(@Nullable Object payload, @Nullable Map<String, Object> props) {
39+
if (payload == null)
40+
throw new IgniteException("Java object class name is not provided.");
41+
42+
assert payload instanceof String;
43+
44+
clsName = (String)payload;
45+
46+
this.props = props;
47+
}
48+
49+
/** {@inheritDoc} */
50+
@Override public T create() {
51+
T res = PlatformUtils.createJavaObject(clsName);
52+
53+
PlatformUtils.initializeJavaObject(res, clsName, props, null);
54+
55+
return res;
56+
}
57+
58+
/** {@inheritDoc} */
59+
@Override public String toString() {
60+
return S.toString(PlatformDefaultJavaObjectFactory.class, this);
61+
}
62+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.processors.platform;
19+
20+
import org.apache.ignite.platform.PlatformJavaObjectFactory;
21+
import org.jetbrains.annotations.Nullable;
22+
23+
import java.util.Map;
24+
25+
/**
26+
* Extended Java object factory interface to handle special cases.
27+
*/
28+
public interface PlatformJavaObjectFactoryEx<T> extends PlatformJavaObjectFactory<T> {
29+
/**
30+
* Initialize factory.
31+
*
32+
* @param payload Optional payload.
33+
* @param props Optional properties.
34+
*/
35+
public void initialize(@Nullable Object payload, @Nullable Map<String, Object> props);
36+
}
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.processors.platform;
19+
20+
import org.apache.ignite.IgniteException;
21+
import org.apache.ignite.binary.BinaryObjectException;
22+
import org.apache.ignite.binary.BinaryReader;
23+
import org.apache.ignite.binary.BinaryWriter;
24+
import org.apache.ignite.binary.Binarylizable;
25+
import org.apache.ignite.internal.GridKernalContext;
26+
import org.apache.ignite.internal.binary.BinaryRawReaderEx;
27+
import org.apache.ignite.internal.binary.BinaryRawWriterEx;
28+
import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
29+
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
30+
import org.apache.ignite.internal.util.typedef.internal.S;
31+
import org.apache.ignite.internal.util.typedef.internal.U;
32+
import org.apache.ignite.platform.PlatformJavaObjectFactory;
33+
import org.jetbrains.annotations.Nullable;
34+
35+
import java.io.Externalizable;
36+
import java.io.IOException;
37+
import java.io.ObjectInput;
38+
import java.io.ObjectOutput;
39+
import java.util.HashMap;
40+
import java.util.Map;
41+
42+
/**
43+
* Wrapper for Java object factory.
44+
*/
45+
public class PlatformJavaObjectFactoryProxy implements Externalizable, Binarylizable {
46+
/** */
47+
private static final long serialVersionUID = 0L;
48+
49+
/** User-defined type. */
50+
public static final int TYP_USER = 0;
51+
52+
/** Default factory. */
53+
public static final int TYP_DEFAULT = 1;
54+
55+
/** Factory type. */
56+
private int factoryTyp;
57+
58+
/** Class name. */
59+
private String clsName;
60+
61+
/** Optional payload for special factory types. */
62+
@GridToStringExclude
63+
private Object payload;
64+
65+
/** Properties. */
66+
@GridToStringExclude
67+
private Map<String, Object> props;
68+
69+
/**
70+
* Default constructor.
71+
*/
72+
public PlatformJavaObjectFactoryProxy() {
73+
// No-op.
74+
}
75+
76+
/**
77+
* Constructor.
78+
*
79+
* @param factoryTyp Factory type.
80+
* @param clsName Class name.
81+
* @param payload Payload.
82+
* @param props Properties.
83+
*/
84+
public PlatformJavaObjectFactoryProxy(int factoryTyp, @Nullable String clsName, @Nullable Object payload,
85+
@Nullable Map<String, Object> props) {
86+
this.factoryTyp = factoryTyp;
87+
this.clsName = clsName;
88+
this.payload = payload;
89+
this.props = props;
90+
}
91+
92+
/**
93+
* Get factory instance.
94+
*
95+
* @param ctx Kernal context for injections.
96+
* @return Factory instance.
97+
*/
98+
public PlatformJavaObjectFactory factory(GridKernalContext ctx) {
99+
// Create factory.
100+
Object res;
101+
102+
switch (factoryTyp) {
103+
case TYP_DEFAULT:
104+
res = new PlatformDefaultJavaObjectFactory();
105+
106+
break;
107+
108+
case TYP_USER:
109+
res = PlatformUtils.createJavaObject(clsName);
110+
111+
break;
112+
113+
default:
114+
throw new IgniteException("Unsupported Java object factory type: " + factoryTyp);
115+
}
116+
117+
// Initialize factory.
118+
if (res instanceof PlatformJavaObjectFactoryEx)
119+
((PlatformJavaObjectFactoryEx)res).initialize(payload, props);
120+
else {
121+
PlatformUtils.initializeJavaObject(res, clsName, props, ctx);
122+
123+
if (!(res instanceof PlatformJavaObjectFactory))
124+
res = new PlatformJavaObjectSingletonFactory<>(res);
125+
}
126+
127+
return (PlatformJavaObjectFactory)res;
128+
}
129+
130+
/** {@inheritDoc} */
131+
@Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
132+
BinaryRawWriterEx rawWriter = (BinaryRawWriterEx)writer.rawWriter();
133+
134+
rawWriter.writeInt(factoryTyp);
135+
rawWriter.writeString(clsName);
136+
rawWriter.writeObjectDetached(payload);
137+
138+
if (props != null) {
139+
rawWriter.writeInt(props.size());
140+
141+
for (Map.Entry<String, Object> prop : props.entrySet()) {
142+
rawWriter.writeString(prop.getKey());
143+
rawWriter.writeObjectDetached(prop.getValue());
144+
}
145+
}
146+
else
147+
rawWriter.writeInt(0);
148+
}
149+
150+
/** {@inheritDoc} */
151+
@Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
152+
BinaryRawReaderEx rawReader = (BinaryRawReaderEx)reader.rawReader();
153+
154+
factoryTyp = rawReader.readInt();
155+
clsName = rawReader.readString();
156+
payload = rawReader.readObjectDetached();
157+
158+
int propsSize = rawReader.readInt();
159+
160+
if (propsSize > 0) {
161+
props = new HashMap<>(propsSize);
162+
163+
for (int i = 0; i < propsSize; i++) {
164+
String key = rawReader.readString();
165+
Object val = rawReader.readObjectDetached();
166+
167+
props.put(key, val);
168+
}
169+
}
170+
}
171+
172+
/** {@inheritDoc} */
173+
@Override public void writeExternal(ObjectOutput out) throws IOException {
174+
out.writeInt(factoryTyp);
175+
U.writeString(out, clsName);
176+
out.writeObject(payload);
177+
U.writeMap(out, props);
178+
}
179+
180+
/** {@inheritDoc} */
181+
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
182+
factoryTyp = in.readInt();
183+
clsName = U.readString(in);
184+
payload = in.readObject();
185+
props = U.readMap(in);
186+
}
187+
188+
/** {@inheritDoc} */
189+
@Override public String toString() {
190+
return S.toString(PlatformJavaObjectFactoryProxy.class, this);
191+
}
192+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.processors.platform;
19+
20+
import org.apache.ignite.internal.util.typedef.internal.S;
21+
import org.apache.ignite.platform.PlatformJavaObjectFactory;
22+
23+
/**
24+
* Singleton factory.
25+
*/
26+
public class PlatformJavaObjectSingletonFactory<T> implements PlatformJavaObjectFactory<T> {
27+
/** Instance. */
28+
private final T instance;
29+
30+
/**
31+
* Constructor.
32+
*
33+
* @param instance Instance.
34+
*/
35+
public PlatformJavaObjectSingletonFactory(T instance) {
36+
this.instance = instance;
37+
}
38+
39+
/** {@inheritDoc} */
40+
@Override public T create() {
41+
return instance;
42+
}
43+
44+
/** {@inheritDoc} */
45+
@Override public String toString() {
46+
return S.toString(PlatformJavaObjectSingletonFactory.class, this);
47+
}
48+
}

0 commit comments

Comments
 (0)