1 | package geniusweb.partiesserver.repository;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 |
|
---|
5 | import geniusweb.actions.PartyId;
|
---|
6 | import geniusweb.javavenv.PythonPartyFactory;
|
---|
7 | import geniusweb.party.Capabilities;
|
---|
8 | import geniusweb.party.Party;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * An approved and ready to run party.
|
---|
12 | */
|
---|
13 | public class AvailablePythonParty implements AvailableParty {
|
---|
14 |
|
---|
15 | private final PythonPartyFactory partyfactory;
|
---|
16 | private final String name;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | *
|
---|
20 | * @param name the filename. This is not a {@link PartyId}.
|
---|
21 | * @param partyfactory the {@link PythonPartyFactory} for the party.
|
---|
22 | */
|
---|
23 | public AvailablePythonParty(String name, PythonPartyFactory partyfactory)
|
---|
24 | throws ClassNotFoundException {
|
---|
25 | this.name = name;
|
---|
26 | this.partyfactory = partyfactory;
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Override
|
---|
30 | public String getID() {
|
---|
31 | return name;
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public String getName() {
|
---|
36 | return name;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | *
|
---|
41 | * @return cached copy of what was received from a call to
|
---|
42 | * {@link Party#getDescription()}.
|
---|
43 | */
|
---|
44 | @Override
|
---|
45 | public String getDescription() {
|
---|
46 | return partyfactory.getDescription();
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | *
|
---|
51 | * @return cached copy of what was received from a call to
|
---|
52 | * {@link AvailableParty#getCapabilities()}
|
---|
53 | */
|
---|
54 | @Override
|
---|
55 | public Capabilities getCapabilities() {
|
---|
56 | return partyfactory.getCapabilites();
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public Party getInstance() throws InstantiationFailedException {
|
---|
61 | try {
|
---|
62 | return partyfactory.getInstance();
|
---|
63 | } catch (IOException e) {
|
---|
64 | throw new InstantiationFailedException(
|
---|
65 | "Failed to create instance of " + name, e);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public void free() {
|
---|
71 | partyfactory.close();
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public int hashCode() {
|
---|
76 | final int prime = 31;
|
---|
77 | int result = 1;
|
---|
78 | result = prime * result + ((name == null) ? 0 : name.hashCode());
|
---|
79 | result = prime * result
|
---|
80 | + ((partyfactory == null) ? 0 : partyfactory.hashCode());
|
---|
81 | return result;
|
---|
82 | }
|
---|
83 |
|
---|
84 | @Override
|
---|
85 | public boolean equals(Object obj) {
|
---|
86 | if (this == obj)
|
---|
87 | return true;
|
---|
88 | if (obj == null)
|
---|
89 | return false;
|
---|
90 | if (getClass() != obj.getClass())
|
---|
91 | return false;
|
---|
92 | AvailablePythonParty other = (AvailablePythonParty) obj;
|
---|
93 | if (name == null) {
|
---|
94 | if (other.name != null)
|
---|
95 | return false;
|
---|
96 | } else if (!name.equals(other.name))
|
---|
97 | return false;
|
---|
98 | if (partyfactory == null) {
|
---|
99 | if (other.partyfactory != null)
|
---|
100 | return false;
|
---|
101 | } else if (!partyfactory.equals(other.partyfactory))
|
---|
102 | return false;
|
---|
103 | return true;
|
---|
104 | }
|
---|
105 |
|
---|
106 | @Override
|
---|
107 | public String toString() {
|
---|
108 | return name + " (" + partyfactory + ")";
|
---|
109 | }
|
---|
110 |
|
---|
111 | }
|
---|