/** * Creates a shell channel to the remote machine a new jsch session is also created if the current * one is invalid * * @param sshContact the contact of the remote machine * @param firstMessage the first message */ public void connectShell(final ContactSSH sshContact, final Message firstMessage) { sshContact.setConnectionInProgress(true); final UIService uiService = this.uiService; final Thread newConnection = new Thread( (new Runnable() { public void run() { OperationSetPersistentPresenceSSHImpl persistentPresence = (OperationSetPersistentPresenceSSHImpl) sshContact.getParentPresenceOperationSet(); persistentPresence.changeContactPresenceStatus( sshContact, SSHStatusEnum.CONNECTING); try { if (!isSessionValid(sshContact)) createSSHSessionAndLogin(sshContact); createShellChannel(sshContact); // initalizing the reader and writers of ssh contact persistentPresence.changeContactPresenceStatus( sshContact, SSHStatusEnum.CONNECTED); showWelcomeMessage(sshContact); sshContact.setMessageType(sshContact.CONVERSATION_MESSAGE_RECEIVED); sshContact.setConnectionInProgress(false); Thread.sleep(1500); sshContact.setCommandSent(true); basicInstantMessaging.sendInstantMessage(sshContact, firstMessage); } // rigoruos Exception Checking in future catch (Exception ex) { persistentPresence.changeContactPresenceStatus( sshContact, SSHStatusEnum.NOT_AVAILABLE); ex.printStackTrace(); } finally { sshContact.setConnectionInProgress(false); } } })); newConnection.start(); }
private void expireLoop() { while (enabled) { // Sleep try { synchronized (sleepLock) { sleepLock.wait(POLL_INTERVAL); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (!enabled) break; // Loop over conferences for (JitsiMeetConference conference : new ArrayList<JitsiMeetConference>(conferences.values())) { long idleStamp = conference.getIdleTimestamp(); // Is active ? if (idleStamp == -1) { continue; } if (System.currentTimeMillis() - idleStamp > timeout) { logger.info("Focus idle timeout for " + conference.getRoomName()); conference.stop(); } } } }
/** * The AIM server doesn't like it if we change states too often and we use this method to slow * things down. */ private void pauseBetweenStateChanges() { try { Thread.sleep(5000); } catch (InterruptedException ex) { logger.debug("Pausing between state changes was interrupted", ex); } }
void stop() { if (timeoutThread == null) { return; } enabled = false; synchronized (sleepLock) { sleepLock.notifyAll(); } try { if (Thread.currentThread() != timeoutThread) { timeoutThread.join(); } timeoutThread = null; } catch (InterruptedException e) { throw new RuntimeException(e); } }
/** * Initializes the server stored list. Synchronize server stored groups and contacts with the * local groups and contacts. */ @Override public void init() { try { SipAccountIDImpl accountID = (SipAccountIDImpl) sipProvider.getAccountID(); if (!accountID.isXiVOEnable()) return; boolean useSipCredentials = accountID.isClistOptionUseSipCredentials(); String serverAddress = accountID.getClistOptionServerUri(); String username = accountID.getAccountPropertyString(ProtocolProviderFactory.USER_ID); Address userAddress = sipProvider.parseAddressString(username); if (useSipCredentials) { username = ((SipUri) userAddress.getURI()).getUser(); } else { username = accountID.getClistOptionUser(); } try { connect(serverAddress); } catch (Throwable ex) { showError(ex, null, null); logger.error("Error connecting to server", ex); return; } Thread thread = new Thread(this, this.getClass().getName()); thread.setDaemon(true); thread.start(); if (!login(username)) { showError(null, null, "Unauthorized. Cannot login."); logger.error("Cannot login."); return; } } catch (Throwable t) { logger.error("Error init clist from xivo server"); } }
void start() { if (timeoutThread != null) { throw new IllegalStateException(); } timeoutThread = new Thread( new Runnable() { @Override public void run() { expireLoop(); } }, "FocusExpireThread"); enabled = true; timeoutThread.start(); }
/** * Implements {@link PacketListener}. Notifies this instance that a specific {@link Packet} (which * this instance has already expressed interest into by returning <tt>true</tt> from {@link * #accept(Packet)}) has been received. * * @param packet the <tt>Packet</tt> which has been received and which this instance is given a * chance to process */ public void processPacket(Packet packet) { /* * As we do elsewhere, acknowledge the receipt of the Packet first and * then go about our business with it. */ IQ iq = (IQ) packet; if (iq.getType() == IQ.Type.SET) protocolProvider.getConnection().sendPacket(IQ.createResultIQ(iq)); /* * Now that the acknowledging is out of the way, do go about our * business with the Packet. */ ColibriConferenceIQ conferenceIQ = (ColibriConferenceIQ) iq; boolean interrupted = false; try { processColibriConferenceIQ(conferenceIQ); } catch (Throwable t) { logger.error( "An error occurred during the processing of a " + packet.getClass().getName() + " packet", t); if (t instanceof InterruptedException) { /* * We cleared the interrupted state of the current Thread by * catching the InterruptedException. However, we do not really * care whether the current Thread has been interrupted - we * caught the InterruptedException because we want to swallow * any Throwable. Consequently, we should better restore the * interrupted state. */ interrupted = true; } else if (t instanceof ThreadDeath) throw (ThreadDeath) t; } if (interrupted) Thread.currentThread().interrupt(); }
/** * Creates a SSH Session with a remote machine and tries to login according to the details * specified by Contact An appropriate message is shown to the end user in case the login fails * * @param sshContact ID of SSH Contact * @throws JSchException if a JSch is unable to create a SSH Session with the remote machine * @throws InterruptedException if the thread is interrupted before session connected or is timed * out * @throws OperationFailedException if not of above reasons :-) */ public void createSSHSessionAndLogin(ContactSSH sshContact) throws JSchException, OperationFailedException, InterruptedException { logger.info("Creating a new SSH Session to " + sshContact.getHostName()); // creating a new JSch Stack identifier for contact JSch jsch = new JSch(); String knownHosts = (String) accountID.getAccountProperties().get("KNOWN_HOSTS_FILE"); if (!knownHosts.equals("Optional")) jsch.setKnownHosts(knownHosts); String identitiyKey = (String) accountID.getAccountProperties().get("IDENTITY_FILE"); String userName = sshContact.getUserName(); // use the name of system user if the contact has not supplied SSH // details if (userName.equals("")) userName = System.getProperty("user.name"); if (!identitiyKey.equals("Optional")) jsch.addIdentity(identitiyKey); // creating a new session for the contact Session session = jsch.getSession( userName, sshContact.getHostName(), sshContact.getSSHConfigurationForm().getPort()); /** * Creating and associating User Info with the session User Info passes authentication from * sshContact to SSH Stack */ SSHUserInfo sshUserInfo = new SSHUserInfo(sshContact); session.setUserInfo(sshUserInfo); /** initializing the session */ session.connect(connectionTimeout); int count = 0; // wait for session to get connected while (!session.isConnected() && count <= 30000) { Thread.sleep(1000); count += 1000; logger.trace("SSH:" + sshContact.getHostName() + ": Sleep zzz .. "); } // if timeout have exceeded if (count > 30000) { sshContact.setSSHSession(null); JOptionPane.showMessageDialog( null, "SSH Connection attempt to " + sshContact.getHostName() + " timed out"); // error codes are not defined yet throw new OperationFailedException( "SSH Connection attempt to " + sshContact.getHostName() + " timed out", 2); } sshContact.setJSch(jsch); sshContact.setSSHSession(session); logger.info("A new SSH Session to " + sshContact.getHostName() + " Created"); }
/** Thread entry point. */ @Override public void run() { int status; long progress; String statusReason = ""; while (true) { try { Thread.sleep(10); status = parseJabberStatus(jabberTransfer.getStatus()); progress = fileTransfer.getTransferedBytes(); if (status == FileTransferStatusChangeEvent.FAILED || status == FileTransferStatusChangeEvent.COMPLETED || status == FileTransferStatusChangeEvent.CANCELED || status == FileTransferStatusChangeEvent.REFUSED) { if (fileTransfer instanceof OutgoingFileTransferJabberImpl) { ((OutgoingFileTransferJabberImpl) fileTransfer).removeThumbnailRequestListener(); } // sometimes a filetransfer can be preparing // and than completed : // transfered in one iteration of current thread // so it won't go through intermediate state - inProgress // make sure this won't happen if (status == FileTransferStatusChangeEvent.COMPLETED && fileTransfer.getStatus() == FileTransferStatusChangeEvent.PREPARING) { fileTransfer.fireStatusChangeEvent( FileTransferStatusChangeEvent.IN_PROGRESS, "Status changed"); fileTransfer.fireProgressChangeEvent(System.currentTimeMillis(), progress); } break; } fileTransfer.fireStatusChangeEvent(status, "Status changed"); fileTransfer.fireProgressChangeEvent(System.currentTimeMillis(), progress); } catch (InterruptedException e) { if (logger.isDebugEnabled()) logger.debug("Unable to sleep thread.", e); } } if (jabberTransfer.getError() != null) { logger.error( "An error occured while transfering file: " + jabberTransfer.getError().getMessage()); } if (jabberTransfer.getException() != null) { logger.error( "An exception occured while transfering file: ", jabberTransfer.getException()); if (jabberTransfer.getException() instanceof XMPPException) { XMPPError error = ((XMPPException) jabberTransfer.getException()).getXMPPError(); if (error != null) if (error.getCode() == 406 || error.getCode() == 403) status = FileTransferStatusChangeEvent.REFUSED; } statusReason = jabberTransfer.getException().getMessage(); } if (initialFileSize > 0 && status == FileTransferStatusChangeEvent.COMPLETED && fileTransfer.getTransferedBytes() < initialFileSize) { status = FileTransferStatusChangeEvent.CANCELED; } fileTransfer.fireStatusChangeEvent(status, statusReason); fileTransfer.fireProgressChangeEvent(System.currentTimeMillis(), progress); }