~ubuntu-branches/ubuntu/precise/triplea/precise

« back to all changes in this revision

Viewing changes to src/games/strategy/engine/message/RemoteMethodCallResults.java

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-11-11 21:40:11 UTC
  • Revision ID: package-import@ubuntu.com-20111111214011-sehf2rwat36o2xqf
Tags: upstream-1.3.2.2
ImportĀ upstreamĀ versionĀ 1.3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This program is free software; you can redistribute it and/or modify
 
3
 * it under the terms of the GNU General Public License as published by
 
4
 * the Free Software Foundation; either version 2 of the License, or
 
5
 * (at your option) any later version.
 
6
 * This program is distributed in the hope that it will be useful,
 
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
9
 * GNU General Public License for more details.
 
10
 * You should have received a copy of the GNU General Public License
 
11
 * along with this program; if not, write to the Free Software
 
12
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
13
 */
 
14
package games.strategy.engine.message;
 
15
 
 
16
import java.io.Externalizable;
 
17
import java.io.IOException;
 
18
import java.io.ObjectInput;
 
19
import java.io.ObjectOutput;
 
20
 
 
21
/**
 
22
 * 
 
23
 *
 
24
 *
 
25
 * @author Sean Bridges
 
26
 */
 
27
/**
 
28
 * The results of a method execution.
 
29
 * 
 
30
 * Note that either one of m_rVal or m_exception will be null,
 
31
 * since the method can either throw or return
 
32
 * 
 
33
 */
 
34
class RemoteMethodCallResults implements Externalizable
 
35
{
 
36
    private Object m_rVal;
 
37
    //throwable implements Serializable
 
38
    private Throwable m_exception;
 
39
    
 
40
    public RemoteMethodCallResults()
 
41
    {
 
42
        
 
43
    }
 
44
    
 
45
    public RemoteMethodCallResults(final Object rVal)
 
46
    {
 
47
        m_rVal = rVal;
 
48
        m_exception = null;
 
49
    }
 
50
 
 
51
    public RemoteMethodCallResults(Throwable exception)
 
52
    {
 
53
        m_rVal = null;
 
54
        m_exception = exception;
 
55
    }
 
56
 
 
57
    public Throwable getException()
 
58
    {
 
59
        return m_exception;
 
60
    }
 
61
    public Object getRVal()
 
62
    {
 
63
        return m_rVal;
 
64
    }
 
65
 
 
66
        public void writeExternal(ObjectOutput out) throws IOException 
 
67
        {        
 
68
        if(m_rVal != null)
 
69
        {
 
70
            out.write(1);
 
71
            out.writeObject(m_rVal);
 
72
        }
 
73
        else
 
74
        {
 
75
            out.write(0);
 
76
            out.writeObject(m_exception);    
 
77
        }
 
78
        }
 
79
 
 
80
        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException 
 
81
        {
 
82
        boolean rVal = in.read() == 1;
 
83
        if(rVal)
 
84
        {
 
85
            m_rVal = in.readObject();
 
86
        }
 
87
        else
 
88
        {
 
89
            m_exception = (Throwable) in.readObject();
 
90
        }
 
91
        }
 
92
}