Tigase Component (一)

 一、创建自己的组件需要实现的接口

        1、tigase.server.ServerComponent – 这是一个非常基本的component接口。所有的component都必须实现接口中定义的方法。

        

/**
 * Interface ServerComponent
 * 这种类型的对象可以被MessageRouter管理.
 * 所有被MessageRouter加载的类必须要实现这个接口。
 */
public interface ServerComponent {
 void setName(String name);
 String getName();
 
 JID getComponentId();
 void release();
 /**
  * processPacket是所有components都必须实现的阻塞性方法.
  * 这个方法处理packet并且不等待任何资源立即返回results
  *
  */
 void processPacket(Packet packet, Queue results);
 void initializationCompleted();
}

    2、tigase.server.MessageReceiver – 这个接口extends ServerComponent,所有希望接收数据packets的Component都需要实现接口中定义的方法,比如session manager和c2s connection manager。

/**
 * Interface MessageReceiver
 * 这种类型的对象可以接收消息,它们事实上也可以根据最终地址进行消息路由。
 * 消息在MessageRouter类中被路由到正确的目的地。
 */
public interface MessageReceiver extends ServerComponent {
 /**
  * 这里缺少方法表述
  *
  * @param packet a Packet value
  * @return 如果packet被成功添加了,返回true。否则否则返回false
  */
boolean addPacket(Packet packet);
boolean addPacketNB(Packet packet);
boolean addPackets(Queue packets);
BareJID getDefHostName();
boolean isInRegexRoutings(String address);
void setParent(MessageReceiver msg_rec);
void start();  

}

    3、tigase.conf.Configurable – 如果希望components可以被配置,则需要实现这个接口。在运行时,配置信息会被推送到这种类型的对象。components必须能够在运行时对变更的配置项进行处理,这一点在实现时要留神。

    

/**
 * Interface Configurable
 *
 * 实现这个接口的对象实例对象是可配置的。 在Tigase系统中组件是不能够请求配置信息的。
 * 配置信息是可以在任何时候被推送到组件。这种方式提供了运行时的动态配置机制。
 */
public interface Configurable extends ServerComponent {
 /**
  * 常量 GEN_CONFIG 是所有配置类型的前缀.
  */
public static final String GEN_CONFIG = "--gen-config";
 /**
  * 常量 GEN_CONFIG_ALL 是所有直接被服务加载的components配置类型的参数名.
  */
public static final String GEN_CONFIG_ALL = GEN_CONFIG + "-all";
 /**
  * 常量 GEN_CONFIG_SM 是session manager的配置信息参数名,
  * 也是 会预先配置并连接到 “具有ClientConnectionMananger的服务实例”
  * XEP-0114 component的配置信息参数名。
  */
public static final String GEN_CONFIG_SM = GEN_CONFIG + "-sm";
 /**
  * 常量 GEN_CONFIG_CS 是 ClientConnectionManager 的配置信息参数名。
  * 也是 会预先配置并连接到 “具有SessionManager的服务实例”
  * 的XEP-0114 component的配置信息参数名。
  */
public static final String GEN_CONFIG_CS = GEN_CONFIG + "-cs";
 /**
  * 常量 GEN_CONFIG_DEF 是 SessionManager,ClientConnectionManager
  * 和ServerConnectionManager的常用配置想参数名。
  */
public static final String GEN_CONFIG_DEF = GEN_CONFIG + "-default";
 
public static final String GEN_CONFIG_COMP = GEN_CONFIG + "-comp";
 /**
  * 常量 CLUSTER_MODE 设置集群工作状态,true 或 false
  * 默认状态下 CLUSTER_MODE 为 false
  */
public static final String CLUSTER_MODE = "--cluster-mode";
 /**
  * 常量 CLUSTER_NODES 用来设置集群中的节点列表
  */
public static final String CLUSTER_NODES = "--cluster-nodes";
 /** Field description */
public static final String CLUSTER_LISTEN = "cluster-listen";
 /** Field description */
public static final String CLUSTER_CONECT = "cluster-connect";
 /** Field description */
public static final String GEN_CONF = "--gen-";
 /** Field description */
public static final String GEN_TEST = "--test";
 /** Field description */
public static final String GEN_COMP_NAME = "--comp-name";
 /** Field description */
public static final String GEN_COMP_CLASS = "--comp-class";
 /** Field description */
public static final String GEN_EXT_COMP = "--ext-comp";
 /** Field description */
public static final String GEN_USER_DB = "--user-db";
 /** Field description */
public static final String USER_REPO_POOL_CLASS = "--user-repo-pool";
 /** Field description */
public static final String USER_DOMAIN_POOL_CLASS = "--user-domain-repo-pool";
 /** Field description */
public static final String GEN_AUTH_DB = "--auth-db";
 /** Field description */
public static final String AUTH_REPO_POOL_CLASS = "--auth-repo-pool";
 /** Field description */
public static final String AUTH_DOMAIN_POOL_CLASS = "--auth-domain-repo-pool";
 /** Field description */
public static final String GEN_USER_DB_URI_PROP_KEY = "user-db-uri";
 /** Field description */
public static final String GEN_USER_DB_URI = "--" + GEN_USER_DB_URI_PROP_KEY;
 /** Field description */
public static final String GEN_AUTH_DB_URI = "--auth-db-uri";
 /** Field description */
public static final String GEN_ADMINS = "--admins";
 /** Field description */
public static final String GEN_TRUSTED = "--trusted";
 /** Field description */
public static final String GEN_VIRT_HOSTS = "--virt-hosts";
 /** Field description */
public static final String GEN_SM_PLUGINS = "--sm-plugins";
 /** Field description */
public static final String GEN_DEBUG = "--debug";
 /** Field description */
public static final String GEN_DEBUG_PACKAGES = "--debug-packages";
 /** Field description */
public static final String GEN_MAX_QUEUE_SIZE = "--max-queue-size";
 /** Field description */
public static final String GEN_SCRIPT_DIR = "--script-dir";
 /** Field description */
public static final String GEN_SREC_DB = "--gen-srec-db";
 /** Field description */
public static final String GEN_SREC_DB_URI = "--gen-srec-db-uri";
 /** Field description */
public static final String GEN_SREC_ADMINS = "--gen-srec-admins";
 /** Field description */
public static final String MONITORING = "--monitoring";
 /** Field description */
public static final String USER_REPO_POOL_SIZE = "--user-repo-pool-size";
 /** Field description */
public static final String STRINGPREP_PROCESSOR = "--stringprep-processor";
 /** Field description */
public static final String XML_REPO_CLASS_PROP_VAL = "tigase.db.xml.XMLRepository";
 /** Field description */
public static final String MYSQL_REPO_CLASS_PROP_VAL = "tigase.db.jdbc.JDBCRepository";
 /** Field description */
public static final String DERBY_REPO_CLASS_PROP_VAL = "tigase.db.jdbc.JDBCRepository";
 /** Field description */
public static final String PGSQL_REPO_CLASS_PROP_VAL = "tigase.db.jdbc.JDBCRepository";
 /** Field description */
public static final String TIGASE_AUTH_REPO_CLASS_PROP_VAL = "tigase.db.jdbc.TigaseAuth";
 /** Field description */
public static final String TIGASE_CUSTOM_AUTH_REPO_CLASS_PROP_VAL = "tigase.db.jdbc.TigaseCustomAuth";
 /** Field description */
public static final String DRUPALWP_REPO_CLASS_PROP_VAL = "tigase.db.jdbc.DrupalWPAuth";
 /** Field description */
public static final String LIBRESOURCE_REPO_CLASS_PROP_VAL = "tigase.db.jdbc.LibreSourceAuth";
 /** Field description */
public static final String SHARED_USER_REPO_PROP_KEY = "shared-user-repo";
 /** Field description */
public static final String SHARED_USER_REPO_PARAMS_PROP_KEY = "shared-user-repo-params";
 /** Field description */
public static final String SHARED_AUTH_REPO_PROP_KEY = "shared-auth-repo";
 /** Field description */
public static final String SHARED_AUTH_REPO_PARAMS_PROP_KEY = "shared-auth-repo-params";
 /** Field description */
public static final String XML_REPO_URL_PROP_VAL = "user-repository.xml";
 /** Field description */
public static final String MYSQL_REPO_URL_PROP_VAL ="jdbc:mysql://localhost/tigase?user=root&password=mypass";
 /** Field description */
public static final String DERBY_REPO_URL_PROP_VAL = "jdbc:derby:tigase-derbydb;create=true";
 /** Field description */
public static final String PGSQL_REPO_URL_PROP_VAL = "jdbc:postgresql://localhost/tigase?user=tigase";
 /** Field description */
public static final String TIGASE_AUTH_REPO_URL_PROP_VAL = "jdbc:mysql://localhost/tigasedb?user=tigase_user&password=mypass";
 /** Field description */
public static final String DRUPAL_REPO_URL_PROP_VAL = "jdbc:mysql://localhost/drupal?user=root&password=mypass";
 /** Field description */
public static final String LIBRESOURCE_REPO_URL_PROP_VAL = "jdbc:postgresql://localhost/libresource?user=demo";
 /** Field description */
public static final String DEF_SM_NAME = "sess-man";
 /** Field description */
public static final String DEF_MONITOR_NAME = "monitor";
 /** Field description */
public static final String DEF_C2S_NAME = "c2s";
 /** Field description */
public static final String DEF_S2S_NAME = "s2s";
 /** Field description */
public static final String DEF_EXT_COMP_NAME = "ext-comp";
 /** Field description */
public static final String DEF_COMP_PROT_NAME = "ext";
 /** Field description */
public static final String DEF_CL_COMP_NAME = "cl-comp";
 /** Field description */
public static final String DEF_SSEND_NAME = "ssend";
 /** Field description */
public static final String DEF_SRECV_NAME = "srecv";
 /** Field description */
public static final String DEF_BOSH_NAME = "bosh";
 /** Field description */
public static final String DEF_STATS_NAME = "stats";
 /** Field description */
public static final String DEF_CLUST_CONTR_NAME = "cluster-contr";
 /** Field description */
public static final String DEF_VHOST_MAN_NAME = "vhost-man";
 /** Field description */
public static final String ROUTER_COMP_CLASS_NAME = "tigase.server.MessageRouter";
 /** Field description */
public static final String C2S_COMP_CLASS_NAME = "tigase.server.xmppclient.ClientConnectionManager";
 /** Field description */
public static final String C2S_CLUST_COMP_CLASS_NAME = "tigase.cluster.ClientConnectionClustered";
 /** Field description */
public static final String S2S_COMP_CLASS_NAME = "tigase.server.xmppserver.S2SConnectionManager";
 /** Field description */
public static final String S2S_CLUST_COMP_CLASS_NAME = "tigase.cluster.S2SConnectionClustered";
 /** Field description */
public static final String SM_COMP_CLASS_NAME = "tigase.server.xmppsession.SessionManager";
 /** Field description */
public static final String SM_CLUST_COMP_CLASS_NAME = "tigase.cluster.SessionManagerClustered";
 /** Field description */
public static final String EXT_COMP_CLASS_NAME = "tigase.server.xmppcomponent.ComponentConnectionManager";
 /** Field description */
public static final String MONITOR_CLASS_NAME = "tigase.server.monitor.MonitorComponent";
 /** Field description */
public static final String MONITOR_CLUST_CLASS_NAME = "tigase.server.monitor.MonitorClustered";
 /** Field description */
public static final String COMP_PROT_CLASS_NAME = "tigase.server.ext.ComponentProtocol";
 /** Field description */
public static final String CL_COMP_CLASS_NAME = "tigase.cluster.ClusterConnectionManager";
 /** Field description */
public static final String SSEND_COMP_CLASS_NAME = "tigase.server.ssender.StanzaSender";
 /** Field description */
public static final String SRECV_COMP_CLASS_NAME = "tigase.server.sreceiver.StanzaReceiver";
 /** Field description */
public static final String BOSH_COMP_CLASS_NAME = "tigase.server.bosh.BoshConnectionManager";
 /** Field description */
public static final String STATS_CLASS_NAME = "tigase.stats.StatisticsCollector";
 /** Field description */
public static final String CLUSTER_CONTR_CLASS_NAME = "tigase.cluster.ClusterController";
 /** Field description */
public static final String VHOST_MAN_CLASS_NAME = "tigase.vhosts.VHostManager";
 /** Field description */
public static final String USER_REPO_URL_PROP_KEY = "user-repo-url";
 /** Field description */
public static final String USER_REPO_PARAMS_NODE = "user-repo-params";
 /** Field description */
public static final String USER_REPO_POOL_SIZE_PROP_KEY = "user-repo-pool-size";
 /** Field description */
public static final String USER_REPO_DOMAINS_PROP_KEY = "user-repo-domains";
 /** Field description */
public static final String AUTH_REPO_DOMAINS_PROP_KEY = "auth-repo-domains";
 /** Field description */
public static final String AUTH_REPO_URL_PROP_KEY = "auth-repo-url";
 /** Field description */
public static final String AUTH_REPO_PARAMS_NODE = "auth-repo-params";
 /** Field description */
public static final String HOSTNAMES_PROP_KEY = "hostnames";
 /** Field description */
public static final String ADMINS_PROP_KEY = "admins";
 /** Field description */
public static final String TRUSTED_PROP_KEY = "trusted";
 /** Field description */
public static final String DEF_HOSTNAME_PROP_KEY = "def-hostname";
 /** Field description */
public static final String COMPONENT_ID_PROP_KEY = "component-id";
 /** Field description */
public static final String CLUSTER_NODES_PROP_KEY = "cluster-nodes";
 //~--- get methods ----------------------------------------------------------
 /**
   * 返回对象的默认配置信息
   * @param params
   * @return
   */
Map getDefaults(Map params);
 //~--- set methods ----------------------------------------------------------
 /**
   * 批量设置配置信息
   * @param properties
   */
void setProperties(Map properties);
}

    4、tigase.disco.XMPPService – 实现了这个对象的类可以对“ServiceDiscovery”请求做出响应。

/**
 * Interface XMPPService
 * <p/>
 * 实现了这个接口的对象可以对“ServiceDiscovery”请求做出应答。
 * ManagerRouter管理所有的“ServiceDiscovery”请求
 */
public interface XMPPService extends ServerComponent {
 
    /**
     * 一个方便的服务发现信息xmlns字符串常量
     */
    public static final String INFO_XMLNS =
            "http://jabber.org/protocol/disco#info";
    /**
     * 一个方便的服务发现对象xmlns字符串常量
     */
    public static final String ITEMS_XMLNS =
            "http://jabber.org/protocol/disco#items";
    /**
     * 一个方便的服务发现 二进制流特性 常量
     */
    public static final String[] DEF_FEATURES = {INFO_XMLNS, ITEMS_XMLNS};
    /**
     * A convenience constant with component features related to ad-hoc commands.
     */
    public static final String[] CMD_FEATURES =
            {
                    "http://jabber.org/protocol/commands", "jabber:x:data"};
 
    /**
     * 为component返回服务发现信息。如果jid是null,那么返回top level的服务发现信息。
     * SessionMananger可以返回top level的服务发现信息,其他component不行。
     *
     * @param node 服务发现的对象节点,如果是null,则返回top level的服务发现信息
     * @param jid  服务发现请求的接收者,“被询问人”
     * @param from 服务发现请求的发出者. “询问人”。一些服务发现信息仅能提供给系统管理器
     * @return returns 一个 XML 元素格式的服务发现数据
     */
    Element getDiscoInfo(String node, JID jid, JID from);
 
    /**
     * 为component返回服务发现对象。 如果jid是空,则返回top level的服务发现对象,
     * SessionMananger可以返回top level的服务发现对象,其他component则返回null。
     *
     * @param node 服务发现的对象节点
     * @param jid  服务发现请求的接收者,“被询问人”
     * @param from 服务发现请求的发出者. “询问人”。一些服务发现对象仅能提供给系统管理器
     * @return 一个服务发现对象的列表,对于top level请求,返回component自己的服务发现对象
     */
    List<Element> getDiscoItems(String node, JID jid, JID from);
 
    /**
     * 获取top level的服务发现特性
     *
     * @param from 请求发出者的地址。 一些服务发现特性仅能返回给系统管理器,
     *             所以component需要检查请求的发起者是不是系统管理器,并返回响应的内容。
     * @return 服务发现特性列表
     */
    List<Element> getDiscoFeatures(JID from);
 
}

    5、tigase.stats.StatisticsContainer – 实现了这个对象的类可以返回运行时的统计信息。任何一个对象都可以实现这个接口用来收集统计信息

public interface StatisticsContainer extends ServerComponent {
    public void getStatistics(StatisticsList list);
}


转载于:https://my.oschina.net/wjwei113/blog/375280

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值