1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.myfaces.push;
21
22 import java.io.Externalizable;
23 import java.io.IOException;
24 import java.io.ObjectInput;
25 import java.io.ObjectOutput;
26 import org.apache.myfaces.push.cdi.WebsocketApplicationSessionHolder;
27
28 /**
29 * This class ensures the Session instance is properly registered into WebsocketApplicationSessionHolder in case
30 * of serialization/deserialization roundtrip.
31 *
32 */
33 public class WebsocketSessionClusterSerializedRestore implements Externalizable
34 {
35 public final static String WEBSOCKET_SESSION_SERIALIZED_RESTORE = "oam.websocket.SR";
36
37 private String channelToken;
38
39 private boolean deserialized = false;
40
41 public WebsocketSessionClusterSerializedRestore()
42 {
43 }
44
45 public WebsocketSessionClusterSerializedRestore(String channelToken)
46 {
47 this.channelToken = channelToken;
48 }
49
50 @Override
51 public void writeExternal(ObjectOutput out) throws IOException
52 {
53 out.writeUTF(this.channelToken);
54
55 }
56
57 @Override
58 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
59 {
60 this.channelToken = in.readUTF();
61 this.deserialized = true;
62 WebsocketApplicationSessionHolder.getRestoredQueue().add(this.channelToken);
63 }
64
65 /**
66 * @return the channelToken
67 */
68 public String getChannelToken()
69 {
70 return channelToken;
71 }
72
73 /**
74 * @param channelToken the channelToken to set
75 */
76 public void setChannelToken(String channelToken)
77 {
78 this.channelToken = channelToken;
79 }
80
81 /**
82 * @return the deserialized
83 */
84 public boolean isDeserialized()
85 {
86 return deserialized;
87 }
88
89 }