001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 package org.apache.directory.server.dns.service; 021 022 023 import java.util.List; 024 025 import org.apache.directory.server.dns.messages.ResourceRecord; 026 import org.apache.directory.server.dns.store.RecordStore; 027 import org.apache.directory.server.i18n.I18n; 028 import org.apache.mina.core.session.IoSession; 029 import org.apache.mina.handler.chain.IoHandlerCommand; 030 import org.slf4j.Logger; 031 import org.slf4j.LoggerFactory; 032 033 034 /** 035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 036 * @version $Rev: 901657 $, $Date: 2010-01-21 12:27:15 +0100 (Thu, 21 Jan 2010) $ 037 */ 038 public class MonitorContext implements IoHandlerCommand 039 { 040 /** the log for this class */ 041 private static final Logger log = LoggerFactory.getLogger( MonitorContext.class ); 042 043 private String contextKey = "context"; 044 045 046 public void execute( NextCommand next, IoSession session, Object message ) throws Exception 047 { 048 if ( log.isDebugEnabled() ) 049 { 050 try 051 { 052 DnsContext dnsContext = ( DnsContext ) session.getAttribute( getContextKey() ); 053 RecordStore store = dnsContext.getStore(); 054 List<ResourceRecord> records = dnsContext.getResourceRecords(); 055 056 StringBuffer sb = new StringBuffer(); 057 sb.append( "Monitoring context:" ); 058 sb.append( "\n\t" + "store: " + store ); 059 sb.append( "\n\t" + "records: " + records ); 060 061 log.debug( sb.toString() ); 062 } 063 catch ( Exception e ) 064 { 065 // This is a monitor. No exceptions should bubble up. 066 log.error( I18n.err( I18n.ERR_154 ), e ); 067 } 068 } 069 070 next.execute( session, message ); 071 } 072 073 074 protected String getContextKey() 075 { 076 return ( this.contextKey ); 077 } 078 }