1 String securityPrincipalName;2 String securityCredentials;3 String initialContextFactoryName;4 String urlPkgPrefixes;5 String providerURL;6 String topicBindingName;7 String tcfBindingName;8 String userName;9 String password;10 booleanlocationInfo;11 12 TopicConnection topicConnection;13 TopicSession topicSession;14 TopicPublisher topicPublisher;15 16 publicvoidactivateOptions() {17 TopicConnectionFactory topicConnectionFactory;18 try{19 Context jndi;20 LogLog.debug("Getting initial context.");21 if(initialContextFactoryName!=null) {22 Properties env=newProperties();23 env.put(Context.INITIAL_CONTEXT_FACTORY,24 initialContextFactoryName);25 if(providerURL!=null) {26 env.put(Context.PROVIDER_URL, providerURL);27 }else{28 LogLog.warn("You have set InitialContextFactoryName option but not the"29 +"ProviderURL. This is likely to cause problems.");30 }31 if(urlPkgPrefixes!=null) {32 env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);33 }34 if(securityPrincipalName!=null) {35 env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);36 if(securityCredentials!=null) {37 env.put(Context.SECURITY_CREDENTIALS,38 securityCredentials);39 }else{40 LogLog.warn("You have set SecurityPrincipalName option but not the"41 +"SecurityCredentials. This is likely to cause problems.");42 }43 }44 jndi=newInitialContext(env);45 }else{46 jndi=newInitialContext();47 }48 LogLog.debug("Looking up ["+tcfBindingName+"]");49 topicConnectionFactory=(TopicConnectionFactory) lookup(jndi,50 tcfBindingName);51 LogLog.debug("About to create TopicConnection.");52 if(userName!=null) {53 topicConnection=topicConnectionFactory.createTopicConnection(54 userName, password);55 }else{56 topicConnection=topicConnectionFactory57 .createTopicConnection();58 }59 LogLog.debug("Creating TopicSession, non-transactional,"60 +"in AUTO_ACKNOWLEDGE mode.");61 topicSession=topicConnection.createTopicSession(false,62 Session.AUTO_ACKNOWLEDGE);63 LogLog.debug("Looking up topic name ["+topicBindingName+"].");64 Topic topic=(Topic) lookup(jndi, topicBindingName);65 LogLog.debug("Creating TopicPublisher.");66 topicPublisher=topicSession.createPublisher(topic);67 LogLog.debug("Starting TopicConnection.");68 topicConnection.start();69 jndi.close();70 }catch(JMSException e) {71 errorHandler.error(72 "Error while activating options for appender named ["73 +name+"].", e, ErrorCode.GENERIC_FAILURE);74 }catch(NamingException e) {75 errorHandler.error(76 "Error while activating options for appender named ["77 +name+"].", e, ErrorCode.GENERIC_FAILURE);78 }catch(RuntimeException e) {79 errorHandler.error(80 "Error while activating options for appender named ["81 +name+"].", e, ErrorCode.GENERIC_FAILURE);82 }83 }84 85 publicvoidappend(LoggingEvent event) {86 if(!checkEntryConditions()) {87 return;88 }89 try{90 ObjectMessage msg=topicSession.createObjectMessage();91 if(locationInfo) {92 event.getLocationInformation();93 }94 msg.setObject(event);95 topicPublisher.publish(msg);96 }catch(JMSException e) {97 errorHandler.error("Could not publish message in JMSAppender ["98 +name+"].", e, ErrorCode.GENERIC_FAILURE);99 }catch(RuntimeException e) {100 errorHandler.error("Could not publish message in JMSAppender ["101 +name+"].", e, ErrorCode.GENERIC_FAILURE);102 }103 }
log4j 源码解析_Log4j源码解析--Appender接口解析
最新推荐文章于 2021-03-02 14:16:58 发布