com.github.ipaas.ifw.jdbc.mbean.DbHealthCheck.java Source code

Java tutorial

Introduction

Here is the source code for com.github.ipaas.ifw.jdbc.mbean.DbHealthCheck.java

Source

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.ipaas.ifw.jdbc.mbean;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.github.ipaas.ifw.jdbc.DbConnectService;

/**
 * @author Chenql
 */
public class DbHealthCheck implements DbHealthCheckMBean {

    public static String TYPE = "DbHealthCheck";

    private DbConnectService dbConnectService;

    /**
     * ?Id
     */
    private String serviceId;

    /**
     * ??
     */
    private String alias = null;

    /**
     * Master??
     */
    private String masterAlias = null;

    /**
     * IP?
     */
    private String ip = null;

    /**
     * ?
     */
    private String port = null;

    /**
     * ???
     * 
     * @return ??
     */
    @Override
    public String getAlias() {
        return alias;
    }

    /**
     * ??
     * 
     * @param alias
     *            -- ??
     */
    public void setAlias(String alias) {
        this.alias = alias;
    }

    /**
     * @return the masterAlias
     */
    @Override
    public String getMasterAlias() {
        return masterAlias;
    }

    /**
     * @param masterAlias
     *            the masterAlias to set
     */
    public void setMasterAlias(String masterAlias) {
        this.masterAlias = masterAlias;
    }

    /**
     * 
     * @param dbConnectService
     *            -- ?
     * @param serviceId
     *            -- ?Id
     * @param alias
     *            -- ??
     * @param masterAlias
     *            -- ??
     * @param ip
     *            -- ip?
     * @param port
     *            -- ?
     */
    public DbHealthCheck(DbConnectService dbConnectService, String serviceId, String alias, String masterAlias,
            String ip, String port) {
        super();
        this.serviceId = serviceId;
        this.dbConnectService = dbConnectService;
        this.alias = alias;
        this.masterAlias = masterAlias;
        this.ip = ip;
        this.port = port;
    }

    @Override
    public String getTargetIp() {
        return ip;
    }

    @Override
    public String getTargetPort() {
        // TODO Auto-generated method stub
        return port;
    }

    @Override
    public String getState() {
        DbCheckServiceImpl dbCheckSvc = new DbCheckServiceImpl();
        return dbCheckSvc.check(this.dbConnectService, alias);
    }

    /**
     * 
     * ?,IP???appid,?
     * 
     * @param o
     *            -- 
     * 
     */
    public boolean equals(Object o) {
        boolean res = false;

        if (o != null && DbHealthCheck.class.isAssignableFrom(o.getClass())) {
            DbHealthCheck s = (DbHealthCheck) o;
            res = new EqualsBuilder().append(ip, s.getTargetIp()).append(port, s.getTargetPort()).isEquals();
        }
        return res;
    }

    /**
     * 
     * ?hashcode??
     * 
     * @return int ?
     */
    public int hashCode() {
        return new HashCodeBuilder(11, 39).append(alias).append(ip).append(port).toHashCode();
    }

    /**
     * toString
     * 
     * @return String
     * 
     */
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("ip", ip).append("port", port)
                .toString();
    }

    /*
     * (non-Javadoc)
     * 
     * @see cn.tianya.fw.mbean.usability.UsabilityMBean#getUri()
     */
    @Override
    public String getUri() {
        String slash = "/";
        StringBuffer sb = new StringBuffer();
        sb.append(slash).append(serviceId).append(slash).append(alias);
        return sb.toString();
    }

    public DbConnectService getDbConnectService() {
        return dbConnectService;
    }

    public void setDbConnectService(DbConnectService dbConnectService) {
        this.dbConnectService = dbConnectService;
    }

    @Override
    public String getServiceId() {
        return serviceId;
    }
}