Spring Custom Listener

Source: Internet
Author: User

One, based on the spring listener, in the Web. XML configuration

Second, put in the collection, call where needed

1, Interface:

Public interface Uumsyncexceptionlistener {
void Uumempsyncexceptionoccur ();
void Uumorgsyncexceptionoccur ();
void Uumrelationexceptionoccur (list<string> relationdatas);
}

2, implements the interface class, provides the Add collection method, and traverses the collection, calls the corresponding method

@Service (value = "Uumsyncexceptiondispatcher")
public class Uumsyncexceptiondispatcher implements Uumsyncexceptionlistener {

Private static final list<uumsyncexceptionlistener> listeners = new arraylist<uumsyncexceptionlistener> () ;

public void AddListener (Uumsyncexceptionlistener listener) {
Listeners.add (listener);
}

@Override
public void Uumempsyncexceptionoccur () {
for (Uumsyncexceptionlistener listener:listeners) {
Listener.uumempsyncexceptionoccur ();
}
}

@Override
public void Uumorgsyncexceptionoccur () {
for (Uumsyncexceptionlistener listener:listeners) {
Listener.uumorgsyncexceptionoccur ();
}
}

@Override
public void Uumrelationexceptionoccur (list<string> relationdatas) {
for (Uumsyncexceptionlistener listener:listeners) {
Listener.uumrelationexceptionoccur (Relationdatas);
}
}
}

3, realize the interface, the concrete realization business processing logic, and joins collection

@Service (value = "Uumrelationsyncexceptionlistener")
public class Uumrelationsyncexceptionlistener implements Uumsyncexceptionlistener {

@Autowired
Syncfaileddatawriter writer;

@Autowired
public void Initialize (
@Qualifier ("Uumsyncexceptiondispatcher") Uumsyncexceptiondispatcher dispatcher) {
Dispatcher.addlistener (this);
}

@Override
public void Uumempsyncexceptionoccur () {
}

@Override
public void Uumorgsyncexceptionoccur () {
}

@Override
public void Uumrelationexceptionoccur (list<string> relationdatas) {
if (Relationdatas! = null &&!relationdatas.isempty ()) {
StringBuilder sb = new StringBuilder ();
for (String Relationdata:relationdatas) {
Sb.append (Relationdata). Append ("\ n");
}
Writer.write ("Relation_", sb.tostring ());
}
}
}

4, call the Traversal collection related method where needed, call the corresponding concrete implementation

@Autowired
Uumsyncexceptiondispatcher Dispatcher;

@Override
protected void Dotranstodb (String msgId, String text) throws Documentexception {
Document document = NULL;
try {
Document = Documenthelper.parsetext (text);
list<element> elements = document.selectnodes ("//ucimrelation");
This.elementcollection (elements);
} catch (Exception e) {
Logger.error ("receiving department head information, parsing XML error", E);
list<string> Faileddatas = new arraylist<string> ();
Faileddatas.add (text);
Dispatcher.uumrelationexceptionoccur (Faileddatas);
throw new Baseexception ("Parse XML error");
}
}

Spring Custom Listener

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.