Line 0
Link Here
|
|
|
1 |
package org.netbeans.modules.ruby.railsprojects.server; |
2 |
|
3 |
import java.io.File; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Collections; |
6 |
import java.util.List; |
7 |
import java.util.concurrent.Future; |
8 |
import javax.swing.JComponent; |
9 |
import javax.swing.event.ChangeListener; |
10 |
import org.netbeans.api.ruby.platform.RubyPlatform; |
11 |
import org.netbeans.modules.ruby.railsprojects.server.nodes.RubyServerNode; |
12 |
import org.netbeans.modules.ruby.railsprojects.server.spi.RubyInstance.OperationState; |
13 |
import org.netbeans.modules.ruby.railsprojects.server.spi.RubyInstance.ServerState; |
14 |
import org.netbeans.spi.server.ServerInstanceImplementation; |
15 |
import org.openide.nodes.Node; |
16 |
import org.openide.util.ChangeSupport; |
17 |
import org.openide.util.NbBundle; |
18 |
import org.openide.util.Parameters; |
19 |
|
20 |
/** |
21 |
* This class represents passenger (gem) installation |
22 |
* |
23 |
* @author Michal Papis |
24 |
*/ |
25 |
class Passenger implements RubyServer, ServerInstanceImplementation { |
26 |
|
27 |
static final String GEM_NAME = "passenger"; |
28 |
static final String SERVER_URI = "PASSENGER"; |
29 |
private final RubyPlatform platform; |
30 |
private final String version; |
31 |
private final List<RailsApplication> applications = new ArrayList<RailsApplication>(); |
32 |
private final ChangeSupport changeSupport = new ChangeSupport(this); |
33 |
private Node node; |
34 |
|
35 |
Passenger(RubyPlatform platform, String version) { |
36 |
Parameters.notNull("platform", platform); //NOI18N |
37 |
this.platform = platform; |
38 |
this.version = version; |
39 |
} |
40 |
|
41 |
private Node getNode() { |
42 |
if (this.node == null) { |
43 |
this.node = new RubyServerNode(this); |
44 |
} |
45 |
return node; |
46 |
} |
47 |
|
48 |
public String getNodeName() { |
49 |
return NbBundle.getMessage(Passenger.class, "LBL_ServerNodeName", getDisplayName(), platform.getLabel()); |
50 |
} |
51 |
|
52 |
public String getLocation() { |
53 |
return null; |
54 |
} |
55 |
|
56 |
public String getStartupParam() { |
57 |
return "passenger"; |
58 |
} |
59 |
|
60 |
public String getScriptPrefix() { |
61 |
return null; |
62 |
} |
63 |
|
64 |
public String getServerPath() { |
65 |
return null; |
66 |
} |
67 |
|
68 |
public boolean isStartupMsg(String arg0) { |
69 |
//Always is started |
70 |
return true; |
71 |
} |
72 |
|
73 |
public List<RailsApplication> getApplications() { |
74 |
return Collections.unmodifiableList(applications); |
75 |
} |
76 |
|
77 |
public boolean addApplication(RailsApplication application) { |
78 |
boolean result = applications.add(application); |
79 |
changeSupport.fireChange(); |
80 |
return result; |
81 |
} |
82 |
|
83 |
/** |
84 |
* Will remove application, instead of http port, the port will carry instance number |
85 |
* @param port |
86 |
* @return |
87 |
*/ |
88 |
public boolean removeApplication(int port) { |
89 |
boolean result = false; |
90 |
for (RailsApplication app : applications) { |
91 |
if (app.getPort() == port) { |
92 |
result = applications.remove(app); |
93 |
changeSupport.fireChange(); |
94 |
break; |
95 |
} |
96 |
} |
97 |
|
98 |
return result; |
99 |
} |
100 |
|
101 |
public void addChangeListener(ChangeListener listener) { |
102 |
changeSupport.addChangeListener(listener); |
103 |
} |
104 |
|
105 |
public void removeChangeListener(ChangeListener listener) { |
106 |
changeSupport.removeChangeListener(listener); |
107 |
} |
108 |
|
109 |
/** |
110 |
* |
111 |
* @return upercase server name |
112 |
* @see ServerResolver.getExplicitlySpecifiedServer(RailsProject project) |
113 |
* @see ServerRegistry.getServer(String serverId, RubyPlatform platform) |
114 |
*/ |
115 |
public String getServerUri() { |
116 |
return "PASSENGER"; |
117 |
} |
118 |
|
119 |
public String getDisplayName() { |
120 |
return NbBundle.getMessage(Passenger.class, "LBL_Passenger",version); |
121 |
} |
122 |
|
123 |
/** |
124 |
* Passenger is meant to be always running, but we could check port if it is listening for connections |
125 |
* @return ServerState.RUNNING |
126 |
* @see RailsServerManager.ensureRunning is currently doing this job |
127 |
*/ |
128 |
public ServerState getServerState() { |
129 |
return ServerState.RUNNING; |
130 |
} |
131 |
|
132 |
public Future<OperationState> startServer(RubyPlatform arg0) { |
133 |
throw new UnsupportedOperationException("Not supported yet."); |
134 |
} |
135 |
|
136 |
public Future<OperationState> stopServer() { |
137 |
throw new UnsupportedOperationException("Not supported yet."); |
138 |
} |
139 |
|
140 |
public Future<OperationState> deploy(String arg0, File arg1) { |
141 |
throw new UnsupportedOperationException("Not supported yet."); |
142 |
} |
143 |
|
144 |
public Future<OperationState> stop(String arg0) { |
145 |
throw new UnsupportedOperationException("Not supported yet."); |
146 |
} |
147 |
|
148 |
public Future<OperationState> runApplication(RubyPlatform arg0, String arg1, File arg2) { |
149 |
throw new UnsupportedOperationException("Not supported yet."); |
150 |
} |
151 |
|
152 |
public boolean isPlatformSupported(RubyPlatform platform) { |
153 |
return this.platform.equals(platform); |
154 |
} |
155 |
|
156 |
public String getContextRoot(String applicationName) { |
157 |
return applicationName; |
158 |
} |
159 |
|
160 |
public int getRailsPort() { |
161 |
return 80; |
162 |
} |
163 |
|
164 |
public String getServerCommand(RubyPlatform arg0, String arg1, File arg2, int arg3, boolean arg4) { |
165 |
throw new UnsupportedOperationException("Not supported yet."); |
166 |
} |
167 |
|
168 |
public String getServerDisplayName() { |
169 |
return getNodeName(); |
170 |
} |
171 |
|
172 |
public Node getFullNode() { |
173 |
return getNode(); |
174 |
} |
175 |
|
176 |
public Node getBasicNode() { |
177 |
return getNode(); |
178 |
} |
179 |
|
180 |
public JComponent getCustomizer() { |
181 |
return null; |
182 |
} |
183 |
|
184 |
public void remove() { |
185 |
throw new UnsupportedOperationException("Not supported yet."); |
186 |
} |
187 |
|
188 |
public boolean isRemovable() { |
189 |
return false; |
190 |
} |
191 |
|
192 |
@Override |
193 |
public boolean equals(Object obj) { |
194 |
if (obj == null) { |
195 |
return false; |
196 |
} |
197 |
if (getClass() != obj.getClass()) { |
198 |
return false; |
199 |
} |
200 |
final Passenger other = (Passenger) obj; |
201 |
if (this.platform != other.platform && (this.platform == null || !this.platform.equals(other.platform))) { |
202 |
return false; |
203 |
} |
204 |
if (this.version != other.version && (this.version == null || !this.version.equals(other.version))) { |
205 |
return false; |
206 |
} |
207 |
return true; |
208 |
} |
209 |
|
210 |
@Override |
211 |
public int hashCode() { |
212 |
int hash = 3; |
213 |
hash = 55 * hash + (this.platform != null ? this.platform.hashCode() : 0); |
214 |
hash = 55 * hash + (this.version != null ? this.version.hashCode() : 0); |
215 |
return hash; |
216 |
} |
217 |
} |