Example usage for com.google.common.collect GenericMapMaker makeComputingMap

List of usage examples for com.google.common.collect GenericMapMaker makeComputingMap

Introduction

In this page you can find the example usage for com.google.common.collect GenericMapMaker makeComputingMap.

Prototype

@Deprecated
abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
        Function<? super K, ? extends V> computingFunction);

Source Link

Document

See MapMaker#makeComputingMap .

Usage

From source file:com.alibaba.otter.node.etl.common.db.dialect.AbstractDbDialect.java

private void initTables(final JdbcTemplate jdbcTemplate) {
    // soft??//from  ww  w  .  java 2 s  . c o  m
    GenericMapMaker mapMaker = null;
    mapMaker = new MapMaker().softValues().evictionListener(new MapEvictionListener<List<String>, Table>() {

        public void onEviction(List<String> names, Table table) {
            logger.warn("Eviction For Table:" + table);
        }
    });

    this.tables = mapMaker.makeComputingMap(new Function<List<String>, Table>() {

        public Table apply(List<String> names) {
            Assert.isTrue(names.size() == 2);
            try {
                beforeFindTable(jdbcTemplate, names.get(0), names.get(0), names.get(1));
                DdlUtilsFilter filter = getDdlUtilsFilter(jdbcTemplate, names.get(0), names.get(0),
                        names.get(1));
                Table table = DdlUtils.findTable(jdbcTemplate, names.get(0), names.get(0), names.get(1),
                        filter);
                afterFindTable(table, jdbcTemplate, names.get(0), names.get(0), names.get(1));
                if (table == null) {
                    throw new NestableRuntimeException(
                            "no found table [" + names.get(0) + "." + names.get(1) + "] , pls check");
                } else {
                    return table;
                }
            } catch (Exception e) {
                throw new NestableRuntimeException(
                        "find table [" + names.get(0) + "." + names.get(1) + "] error", e);
            }
        }
    });
}

From source file:com.alibaba.otter.manager.biz.remote.impl.NodeMBeanServiceImpl.java

public NodeMBeanServiceImpl() {
    try {/*  w  ww  .j a v a2 s  .  c o m*/
        objectName = new ObjectName(MBEAN_NAME);
    } catch (Exception e) {
        throw new ManagerException(e);
    }

    GenericMapMaker mapMaker = null;
    mapMaker = new MapMaker().expireAfterAccess(5, TimeUnit.MINUTES).softValues()
            .evictionListener(new MapEvictionListener<Long, MBeanServerConnection>() {

                public void onEviction(Long nid, MBeanServerConnection mbeanServer) {
                    // do nothing
                }
            });

    mbeanServers = mapMaker.makeComputingMap(new Function<Long, MBeanServerConnection>() {

        public MBeanServerConnection apply(Long nid) {
            Node node = nodeService.findById(nid);
            String ip = node.getIp();
            if (node.getParameters().getUseExternalIp()) {
                ip = node.getParameters().getExternalIp();
            }

            int port = node.getPort().intValue() + 1;
            Integer mbeanPort = node.getParameters().getMbeanPort();
            if (mbeanPort != null && mbeanPort != 0) {// ??<=4.2.2mbeanPort
                port = mbeanPort;
            }

            try {
                JMXServiceURL serviceURL = new JMXServiceURL(
                        MessageFormat.format(SERVICE_URL, ip, String.valueOf(port)));
                JMXConnector cntor = JMXConnectorFactory.connect(serviceURL, null);
                MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
                return mbsc;
            } catch (Exception e) {
                throw new ManagerException(e);
            }
        }

    });
}

From source file:com.alibaba.otter.node.etl.common.db.dialect.DbDialectFactory.java

public DbDialectFactory() {
    // map//  w  ww  . jav  a2 s  .  c  om
    GenericMapMaker mapMaker = null;
    mapMaker = new MapMaker().softValues()
            .evictionListener(new MapEvictionListener<Long, Map<DbMediaSource, DbDialect>>() {

                public void onEviction(Long pipelineId, Map<DbMediaSource, DbDialect> dialect) {
                    if (dialect == null) {
                        return;
                    }

                    for (DbDialect dbDialect : dialect.values()) {
                        dbDialect.destory();
                    }
                }
            });

    dialects = mapMaker.makeComputingMap(new Function<Long, Map<DbMediaSource, DbDialect>>() {

        public Map<DbMediaSource, DbDialect> apply(final Long pipelineId) {
            // map
            return new MapMaker().makeComputingMap(new Function<DbMediaSource, DbDialect>() {

                public DbDialect apply(final DbMediaSource source) {
                    DataSource dataSource = dataSourceService.getDataSource(pipelineId, source);
                    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
                    return (DbDialect) jdbcTemplate.execute(new ConnectionCallback() {

                        public Object doInConnection(Connection c) throws SQLException, DataAccessException {
                            DatabaseMetaData meta = c.getMetaData();
                            String databaseName = meta.getDatabaseProductName();
                            int databaseMajorVersion = meta.getDatabaseMajorVersion();
                            int databaseMinorVersion = meta.getDatabaseMinorVersion();
                            DbDialect dialect = dbDialectGenerator.generate(jdbcTemplate, databaseName,
                                    databaseMajorVersion, databaseMinorVersion, source.getType());
                            if (dialect == null) {
                                throw new UnsupportedOperationException("no dialect for" + databaseName);
                            }

                            if (logger.isInfoEnabled()) {
                                logger.info(String.format("--- DATABASE: %s, SCHEMA: %s ---", databaseName,
                                        (dialect.getDefaultSchema() == null) ? dialect.getDefaultCatalog()
                                                : dialect.getDefaultSchema()));
                            }

                            return dialect;
                        }
                    });

                }
            });
        }
    });

}