PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/core/HazelcastInstanceAwareObject.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 48 lines | 23 code | 10 blank | 15 comment | 0 complexity | 50112fc9646c422ee8fa695661b3879a MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.core;
18
19import com.hazelcast.impl.ThreadContext;
20
21import java.io.*;
22
23public abstract class HazelcastInstanceAwareObject implements HazelcastInstanceAware, Serializable {
24    protected transient HazelcastInstance hazelcastInstance = null;
25
26    public HazelcastInstance getHazelcastInstance() {
27        return hazelcastInstance;
28    }
29
30    public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
31        this.hazelcastInstance = hazelcastInstance;
32    }
33
34    public void writeData(DataOutput out) throws IOException {
35    }
36
37    public void readData(DataInput in) throws IOException {
38        hazelcastInstance = ThreadContext.get().getCurrentFactory();
39    }
40
41    private void writeObject(ObjectOutputStream out) throws IOException {
42        writeData(out);
43    }
44
45    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
46        readData(in);
47    }
48}