???????????????????????????£?????′??????“??????…”?????????????????????
?????????????????????????????????????????????????????????????
?????????????
??????????????????е???????е??????????????????????????????????????????
????????????????????????????????????÷??????????????????????????á???????????á?
?????????????????????????????????е????
????1??????????????????????
????2???????????????????г??????????????
????3???????????????????????????
????????CS?е????????java??????
??????????????????????????????msg?????????????????5?????????????????????????????????£?
????????????
????/**
????* @author Jeff Lee
????* @since 2015-10-21 21:34:21
????* ?????-????????
????*/
????public interface CSCallBack {
????public void process(String status);
????}
????????????
????/**
????* @author Jeff Lee
????* @since 2015-10-21 21:25:14
????* ?????-?????????
????*/
????public class Client implements CSCallBack {
????private Server server;
????public Client(Server server) {
????this.server = server;
????}
????public void sendMsg(final String msg){
????System.out.println("?????????????????" + msg);
????new Thread(new Runnable() {
????@Override
????public void run() {
????server.getClientMsg(Client.this??msg);
????}
????}).start();
????System.out.println("??????????????");
????}
????@Override
????public void process(String status) {
????System.out.println("??????????????????" + status);
????}
????}
???????????:
????/**
????* @author Jeff Lee
????* @since 2015-10-21 21:24:15
????* ?????-?????????
????*/
????public class Server {
????public void getClientMsg(CSCallBack csCallBack ?? String msg) {
????System.out.println("????????????????????????????:" + msg);
????// ????????????????????
????try {
????Thread.sleep(5 * 1000);
????} catch (InterruptedException e) {
????e.printStackTrace();
????}
????System.out.println("?????:??????????????????? 200");
????String status = "200";
????csCallBack.process(status);
????}
????}
??????????
????/**
????* @author Jeff Lee
????* @since 2015-10-21 21:24:15
????* ?????-??????
????*/
????public class CallBackTest {
????public static void main(String[] args) {
????Server server = new Server();
????Client client = new Client(server);
????client.sendMsg("Server??Hello~");
????}
????}
?????????2????? — ?????????£?
?????????????????????Server??Hello~
??????????????????
????????????????????????????????:Server??Hello~
???????????????????????????????5??
????????????????????????????? 200
??????????????????????200
???????????????′??????????????
????1?????????????????????????????????????????
????2??Client??sendMsg?????У??????final?????????????????μ?????????á???????????????
????3??????server??getClientMsg()????????????Client???????????????
?????????????????
????— ????????????gitHub???~
???????????????ó???
???????????????????????????????????????????????
????1??Windows???????????
????2????????????????????????????????????????
????3??Servlet?е?Filter(??????)???????????????????????
???????????? Filter(??????)??Interceptor(??????)??????????????????Java????????????????????????????????????????
???????????????????????????壨??????????????????????????
????????????
???????潲??Filter??Intercepter??????????????????????????????????—???????????????????
?????????????
????GOF??? — “??????????????????????????????????????????????????ж?????????????????????????”?????????????????????????????????????????????????
???????????
??????????????????????????????????????????
?????塢???
?????????????
?????????????????
?????????????????
??????????峽????????????
??????????????????