设为首页收藏本站

Scripts 学盟

 找回密码
 加入学盟

QQ登录

只需一步,快速开始

查看: 5626|回复: 2
打印 上一主题 下一主题

openfire Server Socket Reader [复制链接]

Rank: 8Rank: 8

跳转到指定楼层
1#
那个谁 发表于 2011-7-14 18:59:03 |只看该作者 |倒序浏览
We have also these problems and are restarting our server once per day -- but we are using still OF 3.6.4.  We did not upgrade because problems seem not to be resolved.  Some years ago NIO instead of MINA has been discussed here in the forum (I think it was proposed as GSOC project).  
Currently we are looking into modifying the properties that are used by the following source code.  Maybe this helps you as well.
BTW, We use heavily S2S and are looking therefore also into remote session handling (you may ignore those properties).
  1. 1.1.1  XML Parser
  2. // Set default max buffer size to 1MB. Iflimit is reached then close connection

  3. maxBufferSize =JiveGlobals.getIntProperty(MAX_PROPERTY_NAME[1],1048576);

  4. 1.1.2  Component Connection Handler
  5. getMaxIdleTime()[2] = JiveGlobals.getIntProperty("xmpp.component.idle", 6 * 60 * 1000) / 1000;

  6. getClientIdleTime = JiveGlobals.getIntProperty("xmpp.client.idle", 6 * 60 * 1000) / 1000;

  7. 1.1.3  Stalled Session Filter
  8. /**

  9. * MINA filter that will close sessions thatare failing to read outgoing traffic

  10. * and whose outgoing queue is around 5MB. Usethe system property <tt>session.stalled.cap</tt>

  11. * to set the max number of bytes allowed inthe outgoing queue of a session before considering

  12. * it stalled.

  13. *

  14. * @author Gaston Dombiak

  15. */

  16. int bytesCap = JiveGlobals.getIntProperty("session.stalled.cap", 5242880)[3];

  17. 1.1.4  Server Stanza Handler
  18. boolean needed = JiveGlobals.getBooleanProperty("xmpp.server.certificate.verify", true) &&

  19.                 JiveGlobals.getBooleanProperty("xmpp.server.certificate.verify.chain", true) &&

  20.                 !JiveGlobals.getBooleanProperty("xmpp.server.certificate.accept-selfsigned", false);[4]

  21. 1.1.5  Server Socket Reader
  22. The received packets will berouted using another thread to ensure that many received packets

  23. * could be routed at the same time. To avoidcreating new threads every time a packet is received

  24. * each <tt>ServerSocketReader</tt> instanceuses a {@link ThreadPoolExecutor}. By default the

  25. * maximum number of threads that the executormay have is 50. However, this value may be modified

  26. * by changing the property <b>xmpp.server.processing.max.threads</b>.

  27. int coreThreads = JiveGlobals.getIntProperty("xmpp.server.processing.core.threads", 2);[5]

  28. int maxThreads = JiveGlobals.getIntProperty("xmpp.server.processing.max.threads", 50);

  29. int queueSize = JiveGlobals.getIntProperty("xmpp.server.processing.queue", 50);

  30. 1.1.6  Thread Pool Size
  31. /**

  32. * Thread pool to be used for processingincoming packets when using non-blocking

  33. * connections.

  34. *

  35. * // TODO Change theadpool configuration. Would be nice to have something that can be

  36. * // TODO dynamicallyadjusted to demand and circumstances.

  37. *

  38. * @author Daniele Piras

  39. */

  40. protected IOExecutor() {

  41. // Read poolsize parameter...

  42. int poolSize = JiveGlobals.getIntProperty("tiscali.pool.size", 15);[6]

  43. // Create queue for executor

  44. executeQueue = newLinkedBlockingQueue<Runnable>(10000);

  45. // Create executor

  46. executeMsgPool =newThreadPoolExecutor(poolSize, poolSize, 60, TimeUnit.SECONDS, executeQueue); }

  47. 1.1.7  Client Stanza Handler
  48. /** Handler of XML stanzas sentby clients connected directly to the server. Received packet will

  49. * have their FROM attribute overriden to avoidspoofing.<p>

  50. *

  51. * By default the hostname specified in thestream header sent by clients will not be validated.

  52. * When validated the TO attribute of thestream header has to match the server name or a valid

  53. * subdomain. If the value of the 'to'attribute is not valid then a host-unknown error

  54. * will be returned. To enable the validationset the system property

  55. * <b>xmpp.client.validate.host</b> to true.

  56. *

  57. * @author Gaston Dombiak

  58. */

  59. public class ClientStanzaHandler extends StanzaHandler {

  60. return JiveGlobals.getBooleanProperty("xmpp.client.validate.host",false);

  61. policy =Connection.ClientAuth.valueOf(JiveGlobals.getProperty("xmpp.client.cert.policy", "disabled"));

  62. 1.1.8  DNS Util
  63. String property =JiveGlobals.getProperty("dnsutil.dnsOverride");[7]

  64. 1.1.9  Session Manager
  65. /**

  66. * <p>Routemessage packets throughout the server.</p>

  67. * <p>Routingis based on the recipient and sender addresses. The typical

  68. * packet will often berouted twice, once from the sender to some internal

  69. * server component forhandling or processing, and then back to the router

  70. * to be delivered to it'sfinal destination.</p>

  71. *

  72. * @authorIain Shigeoka

  73. */

  74. public classMessageRouter extends BasicModule {


  75. String jids = JiveGlobals.getProperty("xmpp.forward.admins");


  76. if (JiveGlobals.getBooleanProperty("xmpp.audit.active"))[8]{

  77.   conflictLimit =JiveGlobals.getIntProperty("xmpp.session.conflict-limit", 0);

  78.   JiveGlobals.setProperty("xmpp.session.conflict-limit",Integer.toString(conflictLimit));

  79.   

  80.   String conflictLimitProp =JiveGlobals.getProperty("xmpp.session.conflict-limit");

  81.        OutgoingSessionPromise.getInstance().shutdown();

  82.         if(JiveGlobals.getBooleanProperty("shutdownMessage.enabled")) {

  83.            sendServerMessage(null,LocaleUtils.getLocalizedString("admin.shutdown.now"));

  84.         }

  85. /**

  86.   * Returns true if remoteservers are allowed to have more than one connection to this

  87.   * server. Having morethan one connection may improve number of packets that can be

  88.   * transfered per second.This setting only used by the server dialback mehod.<p>

  89.   *

  90.   * It is highlyrecommended that {@link #getServerSessionTimeout()} isenabled so that

  91.   * dead connections tothis server can be easily discarded.

  92.   *

  93.   * @returntrue if remote servers are allowed to have more than one connection to this

  94.   *   server.

  95.   */

  96. public booleanisMultipleServerConnectionsAllowed() {

  97.   returnJiveGlobals.getBooleanProperty("xmpp.server.session.allowmultiple", true);

  98. }


  99. /**

  100.   * Sets if remote serversare allowed to have more than one connection to this

  101.   * server. Having morethan one connection may improve number of packets that can be

  102.   * transfered per second.This setting only used by the server dialback mehod.<p>

  103.   *

  104.   * It is highlyrecommended that {@link #getServerSessionTimeout()} isenabled so that

  105.   * dead connections tothis server can be easily discarded.

  106.   *

  107.   * @paramallowed true if remote servers are allowed to have more than one connection tothis

  108.   *  server.

  109.   */

  110. public voidsetMultipleServerConnectionsAllowed(booleanallowed) {

  111.   JiveGlobals.setProperty("xmpp.server.session.allowmultiple",Boolean.toString(allowed));

  112.   if(allowed && JiveGlobals.getIntProperty("xmpp.server.session.idle", 10 *60 * 1000) <= 0)

  113.   {

  114.       Log.warn("Allowingmultiple S2S connections for each domain, without setting a " +

  115.               "maximumidle timeout for these connections, is unrecommended! Either " +

  116.               "setxmpp.server.session.allowmultiple to 'false' or change " +

  117.               "xmpp.server.session.idleto a (large) positive value.");

  118.      }

  119. }


  120. /**

  121.   * Sets the number ofmilliseconds to elapse between clearing of idle server sessions.

  122.   *

  123.   * @paramtimeout the number of milliseconds to elapse between clearings.

  124.   */

  125. public voidsetServerSessionTimeout(int timeout) {

  126.   if(getServerSessionTimeout() == timeout) {

  127.       return;

  128.      }

  129.      //Set the new property value

  130.     JiveGlobals.setProperty("xmpp.server.session.timeout",Integer.toString(timeout));

  131. }

  132.      returnJiveGlobals.getIntProperty("xmpp.server.session.timeout", 5 *60 * 1000);

  133.     returnJiveGlobals.getIntProperty("xmpp.server.session.idle", 10 *60 * 1000);
复制代码
1

查看全部评分

分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
分享分享0 收藏收藏0

Rank: 8Rank: 8

2#
那个谁 发表于 2011-7-14 19:00:00 |只看该作者
  1. 1.1.10                 Cache Factory
  2. /**

  3. * Creates Cache objects. The returned cacheswill either be local or clustered

  4. * depending on the clustering enabled settingand a user's license.<p>

  5. * <p/>

  6. * When clustered caching is turned on, cacheusage statistics for all caches

  7. * that have been created are periodicallypublished to the clustered cache

  8. * named "opt-$cacheStats".

  9. *

  10. */

  11. public class CacheFactory {

  12. localCacheFactoryClass =JiveGlobals.getProperty(LOCAL_CACHE_PROPERTY_NAME,

  13.    "org.jivesoftware.util.cache.DefaultLocalCacheStrategy");

  14.         clusteredCacheFactoryClass =JiveGlobals.getProperty(CLUSTERED_CACHE_PROPERTY_NAME,

  15.                 "com.jivesoftware.util.cache.CoherenceClusteredCacheFactory");

  16. /**

  17. * Sets a local property which overrides the maximum cache size asconfigured in coherence-cache-config.xml for the

  18. * supplied cache name.

  19. * @param cacheName the name of the cache to store a value for.

  20. * @param size the maximum cache size.

  21. */

  22. public static void setMaxSizeProperty(String cacheName, long size) {

  23. cacheName = cacheName.replaceAll(" ", "");

  24. JiveGlobals.setProperty("cache." + cacheName + ".size", Long.toString(size));

  25. }



  26. /**

  27. * Sets a local property which overrides the maximum cache entry lifetimeas configured in coherence-cache-config.xml

  28. * for the supplied cache name.

  29. * @param cacheName the name of the cache to store a value for.

  30. * @param lifetime the maximum cache entry lifetime.

  31. */

  32. public static void setMaxLifetimeProperty(String cacheName, long lifetime) {

  33. cacheName = cacheName.replaceAll(" ", "");

  34. JiveGlobals.setProperty(("cache." + cacheName + ".maxLifetime"), Long.toString(lifetime));

  35. }


  36. public static boolean hasMaxLifetimeFromProperty(String cacheName) {

  37. return hasCacheProperty(cacheName, ".maxLifetime");

  38. }


  39. public static void setCacheTypeProperty(String cacheName, String type) {

  40. cacheName = cacheName.replaceAll(" ", "");

  41. JiveGlobals.setProperty("cache." + cacheName + ".type", type);

  42. }


  43. public static String getCacheTypeProperty(String cacheName) {

  44. cacheName = cacheName.replaceAll(" ", "");

  45. return JiveGlobals.getProperty("cache." + cacheName + ".type");

  46. }


  47. public static void setMinCacheSize(String cacheName, long size) {

  48. cacheName = cacheName.replaceAll(" ", "");

  49. JiveGlobals.setProperty("cache." + cacheName + ".min", Long.toString(size));

  50. }


  51. public static long getMinCacheSize(String cacheName) {

  52. return getCacheProperty(cacheName, ".min", 0);

  53. }


  54. private static long getCacheProperty(String cacheName, String suffix, long defaultValue){

  55. // First check if user is overwritingdefault value using a system property for the cache name

  56. String propName = "cache." + cacheName.replaceAll("", "") + suffix;

  57. String sizeProp = JiveGlobals.getProperty(propName);

  58. if (sizeProp == null && cacheNames.containsKey(cacheName)) {

  59. // No system property was foundfor the cache name so try now with short name

  60.       propName = "cache." +cacheNames.get(cacheName) + suffix;

  61.             sizeProp =JiveGlobals.getProperty(propName);

  62.         }

  63.         if (sizeProp != null) {

  64.             try {

  65.                 returnLong.parseLong(sizeProp);

  66.             }

  67.             catch(NumberFormatException nfe) {

  68.                 Log.warn("Unable to parse " + propName + " usingdefault value.");

  69.             }

  70.         }

  71.         // Check if there is a default size value for this cache

  72.         Long defaultSize =cacheProps.get(propName);

  73.         return defaultSize ==null ? defaultValue : defaultSize;

  74.    }

  75. 1.1.11                 Local Outgoing Server Session
  76. boolean useTLS = JiveGlobals.getBooleanProperty("xmpp.server.tls.enabled", true);

  77. boolean needed = JiveGlobals.getBooleanProperty("xmpp.server.certificate.verify", true) &&

  78.             JiveGlobals.getBooleanProperty("xmpp.server.certificate.verify.chain", true) &&

  79.             !JiveGlobals.getBooleanProperty("xmpp.server.certificate.accept-selfsigned", false);

  80.        String policyName =JiveGlobals.getProperty("xmpp.server.compression.policy",

  81.         Connection.CompressionPolicy.disabled.toString());

  82. 1.1.12                 Local Incoming Server Session
  83. String policyName =JiveGlobals.getProperty("xmpp.server.compression.policy",

  84. 1.1.13                 Local Connection Multiplexer Session
  85. String policyName =JiveGlobals.getProperty("xmpp.multiplex.tls.policy",

  86.         Connection.TLSPolicy.disabled.toString());

  87.         tlsPolicy =Connection.TLSPolicy.valueOf(policyName);


  88.         // Set the Compression policy stored as a system property

  89.         policyName = JiveGlobals.getProperty("xmpp.multiplex.compression.policy",

  90.                Connection.CompressionPolicy.disabled.toString());


  91. 1.1.14                 Outgoing Session Promise
  92. int maxThreads = JiveGlobals.getIntProperty("xmpp.server.outgoing.max.threads", 20);

  93. int queueSize = JiveGlobals.getIntProperty("xmpp.server.outgoing.queue", 50);

  94. if (maxThreads < 10) {

  95.    // Ensure that the max number ofthreads in the pool is at least 10

  96.    maxThreads = 10;

  97. }

  98. threadPool =

  99.         newThreadPoolExecutor(maxThreads/4, maxThreads, 60, TimeUnit.SECONDS,

  100.                         new LinkedBlockingQueue<Runnable>(queueSize),

  101.                         newThreadPoolExecutor.CallerRunsPolicy());


  102. // Start the thread that willconsume the queued packets. Each pending packet will

  103. // be actually processed by athread of the pool (when available). If an error occurs

  104. // while creating the remotesession or sending the packet then a packet with error 502

  105. // will be sent to the sender ofthe packet

  106. 1.1.15                 Remote Server Manager
  107.    public static boolean canAccess(String domain) {

  108. // If s2s is disabled then it isnot possible to send packets to remote servers or

  109. // receive packets from remoteservers

  110. if (!JiveGlobals.getBooleanProperty("xmpp.server.socket.active", true)) {

  111.    return false;

  112. }


  113.   /**

  114.      * Returns the number of milliseconds towait to connect to a remote server or read

  115.      * data from a remote server. Defaulttimeout value is 20 seconds. Configure the

  116.      * <tt>xmpp.server.read.timeout</tt> globalproperty to override the default value.

  117.      *

  118.      * @return the numberof milliseconds to wait to connect to a remote server or read

  119.      * data from a remote server.

  120.      */

  121.    public static int getSocketTimeout() {

  122. return JiveGlobals.getIntProperty("xmpp.server.read.timeout", 120000);

  123.    }



  124.    /**

  125.      * Returns the remote port to connect forthe specified remote server. If no port was

  126.      * defined then use the default port (e.g.5269).

  127.      *

  128.      * @param domain thedomain of the remote server to get the remote port to connect to.

  129.      * @return the remoteport to connect for the specified remote server.

  130.      */

  131.    public static int getPortForServer(String domain) {

  132. int port = JiveGlobals.getIntProperty("xmpp.server.socket.remotePort", ConnectionManager.DEFAULT_SERVER_PORT);

  133. RemoteServerConfiguration config =getConfiguration(domain);

  134. if (config != null) {

  135.    port = config.getRemotePort();

  136.    if (port == 0) {

  137.         port = JiveGlobals

  138.                 .getIntProperty("xmpp.server.socket.remotePort", ConnectionManager.DEFAULT_SERVER_PORT);

  139.    }

  140. }

  141. return port;

  142.    }


  143.   /**

  144.      * Returns the permission policy being usedfor new XMPP entities that are trying to

  145.      * connect to the server. There are twotypes of policies: 1) blacklist: where any entity

  146.      * is allowed to connect to the serverexcept for those listed in the black list and

  147.      * 2) whitelist: where only the entitieslisted in the white list are allowed to connect to

  148.      * the server.

  149.      *

  150.      * @return thepermission policy being used for new XMPP entities that are trying to

  151.      * connect to the server.

  152.      */

  153.    public static PermissionPolicy getPermissionPolicy() {

  154. try {

  155.    return PermissionPolicy.valueOf(JiveGlobals.getProperty("xmpp.server.permission",

  156.            PermissionPolicy.blacklist.toString()));

  157.         }

  158.         catch (Exception e){

  159.             Log.error(e.getMessage(), e);

  160.             returnPermissionPolicy.blacklist;

  161.         }

  162.    }
复制代码

使用道具 举报

Rank: 8Rank: 8

3#
那个谁 发表于 2011-7-14 19:00:42 |只看该作者
  1. 1.1.16                 Local Incoming Server Session
  2. /**

  3.      * Returns a new {@link IncomingServerSession} with a domain validated by the Authoritative

  4.      * Server. New domains may be added to thereturned IncomingServerSession after they have

  5.      * been validated. See

  6.      * {@link LocalIncomingServerSession#validateSubsequentDomain(org.dom4j.Element)}. The remote

  7.      * server will be able to send packetsthrough this session whose domains were previously

  8.      * validated.<p>

  9.      *

  10.      * When acting as an Authoritative Serverthis method will verify the requested key

  11.      * and will return null since theunderlying TCP connection will be closed after sending the

  12.      * response to the Receiving Server.<p>

  13.      *

  14.      * @param readerreader of DOM documents on the connection to the remote server.

  15.      * @return anIncomingServerSession that was previously validated against the remote server.

  16.      * @throws IOExceptionif an I/O error occurs while communicating with the remote server.

  17.      * @throwsXmlPullParserException if an error occurs while parsing XML packets.

  18.      */

  19.    public LocalIncomingServerSession createIncomingSession(XMPPPacketReaderreader) throws IOException,


  20.             // Set a read timeout (of 5 seconds) so we don't keep waitingforever

  21.             int soTimeout =socket.getSoTimeout();

  22.            socket.setSoTimeout(RemoteServerManager.getSocketTimeout());

  23. 1.1.17                 Default Connection Provider
  24. public void start() {

  25. proxoolURL = "proxool.openfire:"+getDriver()+":"+getServerURL();

  26. settings = new Properties();

  27. settings.setProperty("proxool.maximum-activetime", Integer.toString(activeTimeout));

  28. settings.setProperty("proxool.maximum-connection-count", Integer.toString(getMaxConnections()));

  29. settings.setProperty("proxool.minimum-connection-count", Integer.toString(getMinConnections()));

  30. settings.setProperty("proxool.maximum-connection-lifetime", Integer.toString((int)(86400000 *

  31.    getConnectionTimeout())));

  32. settings.setProperty("proxool.test-before-use", testBeforeUse.toString());

  33. settings.setProperty("proxool.test-after-use", testAfterUse.toString());

  34. settings.setProperty("proxool.house-keeping-test-sql", testSQL);

  35. settings.setProperty("user", getUsername());

  36. settings.setProperty("password", (getPassword() != null ? getPassword() : ""));

  37. }



  38. driver = JiveGlobals.getXMLProperty("database.defaultProvider.driver");

  39. serverURL = JiveGlobals.getXMLProperty("database.defaultProvider.serverURL");

  40. username = JiveGlobals.getXMLProperty("database.defaultProvider.username");

  41. password = JiveGlobals.getXMLProperty("database.defaultProvider.password");

  42. String minCons = JiveGlobals.getXMLProperty("database.defaultProvider.minConnections");

  43. String maxCons = JiveGlobals.getXMLProperty("database.defaultProvider.maxConnections");

  44. String conTimeout = JiveGlobals.getXMLProperty("database.defaultProvider.connectionTimeout");

  45. testSQL = JiveGlobals.getXMLProperty("database.defaultProvider.testSQL", DbConnectionManager.getTestSQL(driver));

  46. testBeforeUse = JiveGlobals.getXMLProperty("database.defaultProvider.testBeforeUse", true);

  47.   testAfterUse = JiveGlobals.getXMLProperty

复制代码
--------------------------------------------------------------------------------

[1] XMLLeightWeightParser

[2] ComponentConnectionHandler

[3] StalledSessionsFilter

[4] ServerStanzaHandler

[5] ServerSocketReader

[6] IOExecutor

[7] DNSUtil

[8] SessionManager

使用道具 举报

您需要登录后才可以回帖 登录 | 加入学盟

手机版|Scripts 学盟   |

GMT+8, 2024-12-19 14:09 , Processed in 1.094036 second(s), 12 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部