Projects tigase _server server-core Commits b681efcd
ctrl k
  • remove watchdog thread for bosh connection altogether; change writePacketToSocket to actually use specific IO service, change the way how xmpp ping packet is created; resolves #2329

  • Loading...
  • Wojciech Kapcia (Tigase) committed 1 decade ago
    b681efcd
    1 parent 29006a1f
  • src/main/java/tigase/server/ConnectionManager.java
    ■ ■ ■ ■ ■ ■
    skipped 25 lines
    26 26   
    27 27  //~--- non-JDK imports --------------------------------------------------------
    28 28   
     29 + 
    29 30  import java.io.IOException;
    30 31  import java.net.InetSocketAddress;
    31 32  import java.nio.channels.SocketChannel;
    skipped 1 lines
    33 34  import java.util.concurrent.ConcurrentHashMap;
    34 35  import java.util.logging.Level;
    35 36  import java.util.logging.Logger;
     37 + 
    36 38  import javax.script.Bindings;
     39 + 
    37 40  import tigase.annotations.TODO;
    38 41  import tigase.conf.ConfigurationException;
    39 42  import tigase.net.*;
     43 + 
    40 44  import tigase.server.script.CommandIfc;
     45 + 
    41 46  import tigase.stats.StatisticsList;
    42 47  import tigase.util.DataTypes;
    43 48  import tigase.xml.Element;
     49 + 
    44 50  import tigase.xmpp.JID;
    45 51  import tigase.xmpp.XMPPDomBuilderHandler;
    46 52  import tigase.xmpp.XMPPIOService;
     53 + 
    47 54  import static tigase.xmpp.XMPPIOService.DOM_HANDLER;
     55 + 
    48 56  import tigase.xmpp.XMPPIOServiceListener;
     57 + 
    49 58   
    50 59  /**
    51 60   * Describe class ConnectionManager here.
    skipped 143 lines
    195 204   protected static final String WATCHDOG_TIMEOUT = "watchdog_timeout";
    196 205   protected static final String WATCHDOG_PING_TYPE_KEY = "watchdog_ping_type";
    197 206   
    198  - 
    199  - //J+
     207 + protected static final Element pingElement = new Element( "iq",
     208 + new Element[] { new Element( "ping", new String[] { "xmlns" }, new String[] { "urn:xmpp:ping" } ) },
     209 + new String[] { "type", "id" },
     210 + new String[] { "get", "tigase-ping" } );
    200 211   
    201 212   //~--- fields ---------------------------------------------------------------
    202 213   
    skipped 189 lines
    392 403   reconnectService(params, connectionDelay);
    393 404   }
    394 405   waitingTasks.clear();
    395  - watchdog.start();
     406 + if ( null != watchdog ){
     407 + watchdog.start();
     408 + }
    396 409   }
    397 410   
    398 411   @Override
    skipped 435 lines
    834 847   @Override
    835 848   public void setName(String name) {
    836 849   super.setName(name);
     850 + setupWatchdogThread();
     851 + }
     852 + 
     853 + protected void setupWatchdogThread() {
    837 854   watchdog = new Thread(new Watchdog(), "Watchdog - " + getName());
    838 855   watchdog.setDaemon(true);
    839 856   }
    840  - 
    841  - 
    842 857   
    843 858   @Override
    844 859   public void setProperties(Map<String, Object> props) throws ConfigurationException {
    skipped 658 lines
    1503 1518   private class Watchdog
    1504 1519   implements Runnable {
    1505 1520   
    1506  - private final Element pingElement = new Element( "ping",
    1507  - new String[] { "xmlns" },
    1508  - new String[] { "urn:xmpp:ping" } );
    1509  - private long pingCount = 0;
     1521 + Packet pingPacket;
    1510 1522  
    1511 1523   @Override
    1512 1524   public void run() {
    skipped 46 lines
    1559 1571   * ping type. */
    1560 1572   switch ( watchdogPingType ) {
    1561 1573   case XMPP:
    1562  - if (! writePacketToSocket( getPingPacket( service )) ) {
     1574 + pingPacket = Iq.packetInstance( pingElement.clone(),
     1575 + JID.jidInstanceNS( (String) service.getSessionData().get( XMPPIOService.HOSTNAME_KEY ) ),
     1576 + JID.jidInstanceNS( service.getUserJid() ) );
     1577 + if ( !writePacketToSocket( (IO) service, pingPacket ) ){
    1563 1578   // writing failed, stopp service
    1564 1579   ++watchdogStopped;
    1565 1580   service.stop();
    skipped 28 lines
    1594 1609   }
    1595 1610   }
    1596 1611   
    1597  - /**
    1598  - * Creates {@code ping} {@link Packet} addressed to the {@link JID}
    1599  - * pertaining to the {@link XMPPIOService} object passed as argument.
    1600  - *
    1601  - * @param service {@link XMPPIOService} object for which {@code ping} packet
    1602  - * should be generated.
    1603  - *
    1604  - * @return {@code ping} {@link Packet} addressed to the {@link JID} owner of
    1605  - * {@link XMPPIOService}.
    1606  - */
    1607  - private Packet getPingPacket( XMPPIOService service ) {
    1608  - JID from = JID.jidInstanceNS( (String) service.getSessionData().get(XMPPIOService.HOSTNAME_KEY) );
    1609  - JID to = JID.jidInstanceNS( service.getUserJid() );
    1610  - 
    1611  - Element iq = new Element( "iq",
    1612  - new String[] { "type", "id" },
    1613  - new String[] { "get", "tigase-ping-" + pingCount++ } );
    1614  - Packet ping = Packet.packetInstance( iq, from, to );
    1615  - ping.setPacketTo( service.getConnectionId() );
    1616  - ping.getElement().addChild( pingElement );
    1617  - return ping;
    1618  - }
    1619 1612   }
    1620 1613  } // ConnectionManager
    1621 1614   
    skipped 3 lines
  • src/main/java/tigase/server/bosh/BoshConnectionManager.java
    ■ ■ ■ ■ ■
    skipped 220 lines
    221 221   }
    222 222   }
    223 223   
     224 + @Override
     225 + protected void setupWatchdogThread() {
     226 + // having watchdog for bosh connections is not needed
     227 + }
     228 + 
    224 229   protected Map<String,String> preBindSession(Map<String,String> attr) {
    225 230   String hostname = attr.get( TO_ATTR );
    226 231   
    skipped 480 lines
    707 712   setupSidlogger( lvl );
    708 713   log.info("Setting SID log level to: " + lvl);
    709 714   }
    710  - 
    711 715   }
    712 716   
    713 717   //~--- methods --------------------------------------------------------------
    skipped 400 lines
Please wait...
Page is in error, reload to recover