有许多类型的插件,让我们谈谈一般的pourpose. Igniterealtime插件指南
您想要定义一个全新的IQ Stanza来管理UserCustomParam.让我们说:
<iq from="user1@myserver" to="myserver" type="get">
<usercustomparam xmls:"com.records.iq" retrive="favouritecolor">
</iq>
Run Code Online (Sandbox Code Playgroud)
你有什么:
第1步: 定义一个添加新处理程序的插件(实现插件的类)
MyCustomHandler colorshandler;
IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();
iqRouter.addHandler(colorshandler);
Run Code Online (Sandbox Code Playgroud)
第二步:根据需要实现MyCustomHandler(读取数据库,写入数据库,读取服务器端等).
public class MyCustomHandler extends IQHandler {
public static final String NAMESPACE_TICKET_IQ = "com.records.iq";
public static final String TAG_TICKET_IQ = "usercustomparam ";
Run Code Online (Sandbox Code Playgroud)
现在您的服务器已准备好管理您的自定义IQ请求.
到客户端的时间:
步骤3:向您的ProviderManager注册一个IQProvider
ProviderManager.addIQProvider("usercustomparam ","com.records.iq", new IQUserCustomParamProvider());
Run Code Online (Sandbox Code Playgroud)
Step4:根据需要实现您的IQUserCustomParamProvider
public class IQUserCustomParamProvider extends IQProvider<IQUserCustomParam>
Run Code Online (Sandbox Code Playgroud)
进入Provider你将从服务器解析传入的IQ,你将创建一个带有实例参数的IQUserCustomParam
String favouriteColor
Run Code Online (Sandbox Code Playgroud)
Step5:您需要实现IQUserCustomParam
public class IQUserCustomParam extends IQ
private final static String childElementName = "usercustomparam";
private final static String childElementNamespace = "com.records.iq";
public IQUserCustomParam (String color)
{
this(childElementName , childElementNamespace );
this.setType(IQ.Type.result);
this.setFavouriteColor(color);
}
Run Code Online (Sandbox Code Playgroud)
第6步:现在设置它已完成,但是当它来自服务器时你尚未定义何时接受IQUserCustomParam.所以你需要一个StanzaFilter
public class IQUserCustomParamFilter implements StanzaFilter
Run Code Online (Sandbox Code Playgroud)
第7步:当你来自服务器时,你还没有定义如何处理IQUserCustomParam.所以你需要一个StanzaListner
public class IQUserCustomParamListner implements StanzaListener
Run Code Online (Sandbox Code Playgroud)
第8步:最后你必须在连接上注册组合过滤器/列表器:
AbstractXMPPConnection connection = ...;
connection.addAsyncStanzaListener(new PersonalConfigListner(this), new IQMUCConfigTicketFIlter();
Run Code Online (Sandbox Code Playgroud)
如果有帮助,请不要忘记接受答案!