01: /*
02: * SSHTools - Java SSH2 API
03: *
04: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
05: *
06: * Contributions made by:
07: *
08: * Brett Smith
09: * Richard Pernavas
10: * Erwin Bolwidt
11: *
12: * This program is free software; you can redistribute it and/or
13: * modify it under the terms of the GNU General Public License
14: * as published by the Free Software Foundation; either version 2
15: * of the License, or (at your option) any later version.
16: *
17: * This program is distributed in the hope that it will be useful,
18: * but WITHOUT ANY WARRANTY; without even the implied warranty of
19: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20: * GNU General Public License for more details.
21: *
22: * You should have received a copy of the GNU General Public License
23: * along with this program; if not, write to the Free Software
24: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25: */
26: package com.sshtools.j2ssh.sftp;
27:
28: import com.sshtools.j2ssh.io.UnsignedInteger32;
29: import com.sshtools.j2ssh.subsystem.SubsystemMessage;
30: import com.sshtools.j2ssh.subsystem.SubsystemMessageStore;
31: import com.sshtools.j2ssh.util.OpenClosedState;
32:
33: import org.apache.commons.logging.Log;
34: import org.apache.commons.logging.LogFactory;
35:
36: import java.util.Iterator;
37:
38: class SftpMessageStore extends SubsystemMessageStore {
39: /** */
40: public static Log log = LogFactory.getLog(SftpMessageStore.class);
41:
42: /**
43: * Creates a new SftpMessageStore object.
44: */
45: public SftpMessageStore() {
46: }
47:
48: /**
49: *
50: *
51: * @param requestId
52: *
53: * @return
54: *
55: * @throws InterruptedException
56: */
57: public synchronized SubsystemMessage getMessage(
58: UnsignedInteger32 requestId) throws InterruptedException {
59: Iterator it;
60: SubsystemMessage msg;
61:
62: // If there ae no messages available then wait untill there are.
63: while (getState().getValue() == OpenClosedState.OPEN) {
64: if (messages.size() > 0) {
65: it = messages.iterator();
66:
67: while (it.hasNext()) {
68: msg = (SubsystemMessage) it.next();
69:
70: if (msg instanceof MessageRequestId) {
71: if (((MessageRequestId) msg).getId().equals(
72: requestId)) {
73: messages.remove(msg);
74:
75: return msg;
76: }
77: }
78: }
79: }
80:
81: log.debug("Waiting for new messages");
82: wait(5000);
83: }
84:
85: return null;
86: }
87: }
|