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 */
020package org.apache.directory.server.dns.service;
021
022
023import java.util.List;
024
025import org.apache.directory.server.dns.messages.ResourceRecord;
026import org.apache.directory.server.dns.store.RecordStore;
027import org.apache.directory.server.i18n.I18n;
028import org.apache.mina.core.session.IoSession;
029import org.apache.mina.handler.chain.IoHandlerCommand;
030import org.slf4j.Logger;
031import org.slf4j.LoggerFactory;
032
033
034/**
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 */
037public class MonitorContext implements IoHandlerCommand
038{
039    /** the log for this class */
040    private static final Logger LOG = LoggerFactory.getLogger( MonitorContext.class );
041
042    private String contextKey = "context";
043
044
045    public void execute( NextCommand next, IoSession session, Object message ) throws Exception
046    {
047        if ( LOG.isDebugEnabled() )
048        {
049            try
050            {
051                DnsContext dnsContext = ( DnsContext ) session.getAttribute( getContextKey() );
052                RecordStore store = dnsContext.getStore();
053                List<ResourceRecord> records = dnsContext.getResourceRecords();
054
055                StringBuilder sb = new StringBuilder();
056                sb.append( "Monitoring context:" );
057                sb.append( "\n\t" + "store:                     " + store );
058                sb.append( "\n\t" + "records:                   " + records );
059
060                LOG.debug( sb.toString() );
061            }
062            catch ( Exception e )
063            {
064                // This is a monitor.  No exceptions should bubble up.
065                LOG.error( I18n.err( I18n.ERR_154 ), e );
066            }
067        }
068
069        next.execute( session, message );
070    }
071
072
073    protected String getContextKey()
074    {
075        return ( this.contextKey );
076    }
077}