hefeixia
2021-02-18 5b8c95c760840f09910730943b21391e47187315
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package chat.server.call;
 
import java.lang.reflect.Method;
 
import org.apache.log4j.Logger;
 
import chat.server.im.DataPool;
import chat.server.im.ResultPool;
import chat.user.Session;
import chat.user.User;
 
 
public abstract class CallObject extends MethodPublisher {
 
    protected static Logger logger;
    protected Session session;
    protected User user;
    protected DataPool dataPool;
    protected ResultPool resultPool;
    
    static {
        logger = Logger.getLogger(CallObject.class);
    }
    
    public CallObject() {
 
    }
    
    public void exec(Session session, Operator operator, DataPool dataPool, ResultPool resultPool) {
        try {
            Method method = getOneMethod(operator.getMethod());
            
            if (method == null) {
                method = methodMap.get("call");
            }
            
            if (method != null) {
                this.session = session;
                
                if (session != null) {
                    this.user = session.getUser();
                }
                
                this.dataPool = dataPool;
                this.resultPool = resultPool;
                
                try {
                    method.invoke(this);
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else {
                resultPool.error(ResultCode.Error_Path_NotExists);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    protected void onError(Exception e) throws Exception {
        logger.error(e);
        
        if (logger.isTraceEnabled()) {
            e.printStackTrace();
        }
    }
 
}