Skip to content

Commit b2cf4e3

Browse files
author
Alex Huang
committed
propagate fix from 2.2.4
1 parent 117a81a commit b2cf4e3

5 files changed

Lines changed: 38 additions & 18 deletions

File tree

server/src/com/cloud/agent/manager/AgentAttache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
public abstract class AgentAttache {
5959
private static final Logger s_logger = Logger.getLogger(AgentAttache.class);
6060

61-
private static final ScheduledExecutorService s_executor = Executors.newScheduledThreadPool(10, new NamedThreadFactory("ListenerTimer"));
61+
private static final ScheduledExecutorService s_listenerExecutor = Executors.newScheduledThreadPool(10, new NamedThreadFactory("ListenerTimer"));
6262

6363
protected static final Comparator<Request> s_reqComparator =
6464
new Comparator<Request>() {
@@ -206,7 +206,7 @@ protected void registerListener(final long seq, final Listener listener) {
206206
s_logger.trace(log(seq, "Registering listener"));
207207
}
208208
if (listener.getTimeout() != -1) {
209-
s_executor.schedule(new Alarm(seq), listener.getTimeout(), TimeUnit.SECONDS);
209+
s_listenerExecutor.schedule(new Alarm(seq), listener.getTimeout(), TimeUnit.SECONDS);
210210
}
211211
_waitForList.put(seq, listener);
212212
}

server/src/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,14 @@ protected AgentAttache handleDirectConnect(ServerResource resource, StartupComma
505505
long id = server.getId();
506506

507507
AgentAttache attache = createAttache(id, server, resource);
508+
if (attache.isReady()) {
509+
StartupAnswer[] answers = new StartupAnswer[startup.length];
510+
for (int i = 0; i < answers.length; i++) {
511+
answers[i] = new StartupAnswer(startup[i], attache.getId(), _pingInterval);
512+
}
513+
514+
attache.process(answers);
515+
}
508516

509517
attache = notifyMonitorsOfConnection(attache, startup);
510518

@@ -1838,14 +1846,6 @@ protected AgentAttache simulateStart(Long id, ServerResource resource, Map<Strin
18381846
resource.disconnected();
18391847
return null;
18401848
}
1841-
if (attache.isReady()) {
1842-
StartupAnswer[] answers = new StartupAnswer[cmds.length];
1843-
for (int i = 0; i < answers.length; i++) {
1844-
answers[i] = new StartupAnswer(cmds[i], attache.getId(), _pingInterval);
1845-
}
1846-
1847-
attache.process(answers);
1848-
}
18491849
return attache;
18501850
}
18511851

server/src/com/cloud/agent/manager/ConnectedAgentAttache.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,18 @@ public boolean equals(Object obj) {
7575
ConnectedAgentAttache that = (ConnectedAgentAttache) obj;
7676
return super.equals(obj) && this._link == that._link && this._link != null;
7777
} catch (ClassCastException e) {
78-
assert false : "Who's sending an " + obj.getClass().getSimpleName() + " to AgentAttache.equals()? ";
78+
assert false : "Who's sending an " + obj.getClass().getSimpleName() + " to " + this.getClass().getSimpleName() + ".equals()? ";
7979
return false;
8080
}
81-
}
81+
}
82+
83+
@Override
84+
public void finalize() {
85+
assert _link == null : "Duh...Says you....Forgot to call disconnect()!";
86+
synchronized(this) {
87+
if (_link != null) {
88+
disconnect(Status.Alert);
89+
}
90+
}
91+
}
8292
}

server/src/com/cloud/agent/manager/DirectAgentAttache.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class DirectAgentAttache extends AgentAttache {
4444
private final static Logger s_logger = Logger.getLogger(DirectAgentAttache.class);
4545

4646
ServerResource _resource;
47-
static ScheduledExecutorService _executor = new ScheduledThreadPoolExecutor(100, new NamedThreadFactory("DirectAgent"));
47+
static ScheduledExecutorService s_executor = new ScheduledThreadPoolExecutor(100, new NamedThreadFactory("DirectAgent"));
4848
List<ScheduledFuture<?>> _futures = new ArrayList<ScheduledFuture<?>>();
4949
AgentManagerImpl _mgr;
5050
long _seq = 0;
@@ -98,15 +98,15 @@ public void send(Request req) throws AgentUnavailableException {
9898
if (answers != null && answers[0] instanceof StartupAnswer) {
9999
StartupAnswer startup = (StartupAnswer)answers[0];
100100
int interval = startup.getPingInterval();
101-
_futures.add(_executor.scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
101+
_futures.add(s_executor.scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
102102
}
103103
} else {
104104
Command[] cmds = req.getCommands();
105105
if (cmds.length > 0 && !(cmds[0] instanceof CronCommand)) {
106-
_executor.execute(new Task(req));
106+
s_executor.execute(new Task(req));
107107
} else {
108108
CronCommand cmd = (CronCommand)cmds[0];
109-
_futures.add(_executor.scheduleAtFixedRate(new Task(req), cmd.getInterval(), cmd.getInterval(), TimeUnit.SECONDS));
109+
_futures.add(s_executor.scheduleAtFixedRate(new Task(req), cmd.getInterval(), cmd.getInterval(), TimeUnit.SECONDS));
110110
}
111111
}
112112
}
@@ -117,10 +117,20 @@ public void process(Answer[] answers) {
117117
StartupAnswer startup = (StartupAnswer)answers[0];
118118
int interval = startup.getPingInterval();
119119
s_logger.info("StartupAnswer received " + startup.getHostId() + " Interval = " + interval );
120-
_futures.add(_executor.scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
120+
_futures.add(s_executor.scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
121121
}
122122
}
123123

124+
@Override
125+
protected void finalize() {
126+
assert _resource == null : "Come on now....If you're going to dabble in agent code, you better know how to close out our resources. Ever considered why there's a method called disconnect()?";
127+
synchronized(this) {
128+
if (_resource != null) {
129+
disconnect(Status.Alert);
130+
}
131+
}
132+
}
133+
124134
protected class PingTask implements Runnable {
125135
@Override
126136
public synchronized void run() {

utils/src/com/cloud/utils/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class StringUtils {
2828
public static String join(Iterable<? extends Object> iterable, String delim) {
2929
StringBuilder sb = new StringBuilder();
3030
if (iterable != null) {
31-
Iterator iter = iterable.iterator();
31+
Iterator<? extends Object> iter = iterable.iterator();
3232
if (iter.hasNext()) {
3333
Object next = iter.next();
3434
sb.append(next.toString());

0 commit comments

Comments
 (0)