paulwong

          #

          NETTY資源

          Netty4.0學習筆記系列之一:Server與Client的通訊

          Netty4.0學習筆記系列之二:Handler的執行順序


          Netty4.0學習筆記系列之三:構建簡單的http服務


          Netty4.0學習筆記系列之四:混合使用coder和handler


          Netty4.0學習筆記系列之五:自定義通訊協議

          Netty4.0學習筆記系列之六:多種通訊協議支持


          NETTY HTTP JAX-RS服務器
          https://github.com/continuuity/netty-http

          netty和tomcat的hello world性能比較
          http://my.oschina.net/u/2302546/blog/368685

          nginx+tomcat與netty優缺點


          NETTY官方EXAMPLE
          https://github.com/netty/netty/tree/4.0/example/src/main/java/io/netty/example


          posted @ 2015-02-26 09:49 paulwong 閱讀(474) | 評論 (0)編輯 收藏

          SPRING CACHE之ConcurrentMapCacheManager改造

          ConcurrentMapCacheManager可以作為一種緩存方案,但不能設置過期,最大緩存條目等,需進行改造。
          1. pom.xml中加入依賴包
                    <dependency>
                        <groupId>com.google.guava</groupId>
                        <artifactId>guava</artifactId>
                        <version>18.0</version>
                    </dependency>

          2. 改造CacheManager,MyConcurrentMapCacheManager
            package com.paul.common.cache;
            /*
             * Copyright 2002-2014 the original author or authors.
             *
             * 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.
             
            */

            import java.util.Collection;
            import java.util.Collections;
            import java.util.Map;
            import java.util.concurrent.ConcurrentHashMap;
            import java.util.concurrent.ConcurrentMap;
            import java.util.concurrent.TimeUnit;

            import org.springframework.cache.Cache;
            import org.springframework.cache.CacheManager;
            import org.springframework.cache.concurrent.ConcurrentMapCache;

            import com.google.common.cache.CacheBuilder;

            /**
             * {
            @link CacheManager} implementation that lazily builds {@link ConcurrentMapCache}
             * instances for each {
            @link #getCache} request. Also supports a 'static' mode where
             * the set of cache names is pre-defined through {
            @link #setCacheNames}, with no
             * dynamic creation of further cache regions at runtime.
             *
             * <p>Note: This is by no means a sophisticated CacheManager; it comes with no
             * cache configuration options. However, it may be useful for testing or simple
             * caching scenarios. For advanced local caching needs, consider
             * {
            @link org.springframework.cache.guava.GuavaCacheManager} or
             * {
            @link org.springframework.cache.ehcache.EhCacheCacheManager}.
             *
             * 
            @author Juergen Hoeller
             * 
            @since 3.1
             * 
            @see ConcurrentMapCache
             
            */
            public class MyConcurrentMapCacheManager implements CacheManager {

                private final ConcurrentMap<String, Cache> cacheMap = new ConcurrentHashMap<String, Cache>(16);

                private boolean dynamic = true;

                private boolean allowNullValues = true;
                
                private long expireTime = 30;
                
                private long maximumSize = 100;


                /**
                 * Construct a dynamic ConcurrentMapCacheManager,
                 * lazily creating cache instances as they are being requested.
                 
            */
                public MyConcurrentMapCacheManager() {
                }

                /**
                 * Construct a static ConcurrentMapCacheManager,
                 * managing caches for the specified cache names only.
                 
            */
                public MyConcurrentMapCacheManager(long expireTime, long maximumSize) {
                    if(expireTime > 0)
                        this.expireTime = expireTime;
                    if(maximumSize > 0)
                        this.maximumSize = maximumSize;
                }


                /**
                 * Specify the set of cache names for this CacheManager's 'static' mode.
                 * <p>The number of caches and their names will be fixed after a call to this method,
                 * with no creation of further cache regions at runtime.
                 * <p>Calling this with a {
            @code null} collection argument resets the
                 * mode to 'dynamic', allowing for further creation of caches again.
                 
            */
                public void setCacheNames(Collection<String> cacheNames) {
                    if (cacheNames != null) {
                        for (String name : cacheNames) {
                            this.cacheMap.put(name, createConcurrentMapCache(name));
                        }
                        this.dynamic = false;
                    }
                    else {
                        this.dynamic = true;
                    }
                }

                /**
                 * Specify whether to accept and convert {
            @code null} values for all caches
                 * in this cache manager.
                 * <p>Default is "true", despite ConcurrentHashMap itself not supporting {
            @code null}
                 * values. An internal holder object will be used to store user-level {
            @code null}s.
                 * <p>Note: A change of the null-value setting will reset all existing caches,
                 * if any, to reconfigure them with the new null-value requirement.
                 
            */
                public void setAllowNullValues(boolean allowNullValues) {
                    if (allowNullValues != this.allowNullValues) {
                        this.allowNullValues = allowNullValues;
                        // Need to recreate all Cache instances with the new null-value configuration
                        for (Map.Entry<String, Cache> entry : this.cacheMap.entrySet()) {
                            entry.setValue(createConcurrentMapCache(entry.getKey()));
                        }
                    }
                }

                /**
                 * Return whether this cache manager accepts and converts {
            @code null} values
                 * for all of its caches.
                 
            */
                public boolean isAllowNullValues() {
                    return this.allowNullValues;
                }


                @Override
                public Collection<String> getCacheNames() {
                    return Collections.unmodifiableSet(this.cacheMap.keySet());
                }

                @Override
                public Cache getCache(String name) {
                    Cache cache = this.cacheMap.get(name);
                    if (cache == null && this.dynamic) {
                        synchronized (this.cacheMap) {
                            cache = this.cacheMap.get(name);
                            if (cache == null) {
                                cache = createConcurrentMapCache(name);
                                this.cacheMap.put(name, cache);
                            }
                        }
                    }
                    return cache;
                }

                /**
                 * Create a new ConcurrentMapCache instance for the specified cache name.
                 * 
            @param name the name of the cache
                 * 
            @return the ConcurrentMapCache (or a decorator thereof)
                 
            */
                protected Cache createConcurrentMapCache(String name) {
                    //return new ConcurrentMapCache(name, isAllowNullValues());
                    //此處改用GOOGLE GUAVA的構造MANAGER方式
                    return new ConcurrentMapCache(name,
                                                    CacheBuilder.newBuilder()
                                                                .expireAfterWrite(this.expireTime, TimeUnit.MINUTES)
                                                                .maximumSize(this.maximumSize)
                                                                .build()
                                                                .asMap(), 
                                                    isAllowNullValues());
                }

            }


          3. 配置想著bean, cache-concurrentmap-applicationcontext.xml
            <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi
            ="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
                xmlns:cache
            ="http://www.springframework.org/schema/cache"
                xmlns:p
            ="http://www.springframework.org/schema/p"
                xmlns:c
            ="http://www.springframework.org/schema/c"
                xmlns:jee
            ="http://www.springframework.org/schema/jee"
                xmlns:util
            ="http://www.springframework.org/schema/util"
                xsi:schemaLocation
            ="http://www.springframework.org/schema/context
                      http://www.springframework.org/schema/context/spring-context-3.0.xsd
                      http://www.springframework.org/schema/beans
                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                      http://www.springframework.org/schema/cache
                      http://www.springframework.org/schema/cache/spring-cache.xsd
                      http://www.springframework.org/schema/jee 
                      http://www.springframework.org/schema/jee/spring-jee.xsd
                      http://www.springframework.org/schema/util
                      http://www.springframework.org/schema/util/spring-util.xsd"
            >

                <cache:annotation-driven />

                <!-- <bean id="cacheManager"
                    class="org.springframework.cache.concurrent.ConcurrentMapCacheManager" >
                    <property name="cacheNames">
                        <list>
                            <value>my-local-cache</value>
                        </list>
                    </property>
                </bean> 
            -->
                
                <bean id="cacheManager"
                    class
            ="com.paul.common.cache.MyConcurrentMapCacheManager">
                    <constructor-arg index="0" value="1" />
                    <constructor-arg index="1" value="5000" />
                </bean>    
                
            </beans>


          4. 通過注釋進行使用
            /*
             * JBoss, Home of Professional Open Source
             * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
             * contributors by the @authors tag. See the copyright.txt in the
             * distribution for a full listing of individual contributors.
             *
             * 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.paul.springmvc.data;

            import java.util.List;

            import javax.persistence.EntityManager;
            import javax.persistence.criteria.CriteriaBuilder;
            import javax.persistence.criteria.CriteriaQuery;
            import javax.persistence.criteria.Root;

            import org.springframework.beans.factory.annotation.Autowired;
            import org.springframework.cache.annotation.CacheEvict;
            import org.springframework.cache.annotation.Cacheable;
            import org.springframework.stereotype.Repository;
            import org.springframework.transaction.annotation.Transactional;

            import com.paul.springmvc.model.Member;

            @Repository
            @Transactional
            public class MemberDaoImpl implements MemberDao {
                @Autowired
                private EntityManager em;

                @Cacheable(value = "my-local-cache", key = "#id")
                public Member findById(Long id) {
                    System.out.println("MemberDaoImpl NO CACHE");
                    return em.find(Member.class, id);
                }

                public Member findByEmail(String email) {
                    CriteriaBuilder cb = em.getCriteriaBuilder();
                    CriteriaQuery<Member> criteria = cb.createQuery(Member.class);
                    Root<Member> member = criteria.from(Member.class);

                    /*
                     * Swap criteria statements if you would like to try out type-safe criteria queries, a new
                     * feature in JPA 2.0 criteria.select(member).orderBy(cb.asc(member.get(Member_.name)));
                     
            */

                    criteria.select(member).where(cb.equal(member.get("email"), email));
                    return em.createQuery(criteria).getSingleResult();
                }

                public List<Member> findAllOrderedByName() {
                    CriteriaBuilder cb = em.getCriteriaBuilder();
                    CriteriaQuery<Member> criteria = cb.createQuery(Member.class);
                    Root<Member> member = criteria.from(Member.class);

                    /*
                     * Swap criteria statements if you would like to try out type-safe criteria queries, a new
                     * feature in JPA 2.0 criteria.select(member).orderBy(cb.asc(member.get(Member_.name)));
                     
            */

                    criteria.select(member).orderBy(cb.asc(member.get("name")));
                    return em.createQuery(criteria).getResultList();
                }

                @CacheEvict(value="my-local-cache",allEntries=true,beforeInvocation=true)//清空所有緩存
                public void register(Member member) {
                    em.persist(member);
                    return;
                }
            }

          posted @ 2015-02-25 16:34 paulwong 閱讀(2699) | 評論 (0)編輯 收藏

          SPRING CACHE資源

          SPRING手冊
          http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/htmlsingle/#cache


          SPRING CONCURRENTMAP MANAGER加過期策略
          http://stackoverflow.com/questions/8181768/can-i-set-a-ttl-for-cacheable

          組合KEY
          http://stackoverflow.com/questions/14072380/cacheable-key-on-multiple-method-arguments

          Spring Cache抽象詳解
          http://www.open-open.com/lib/view/open1389575623336.html

          注釋驅動的 Spring cache 緩存介紹
          https://www.ibm.com/developerworks/cn/opensource/os-cn-spring-cache/

          Spring Cache抽象詳解

          posted @ 2015-02-25 16:04 paulwong 閱讀(506) | 評論 (0)編輯 收藏

          Spring Boot使用redis做數據緩存

          1 添加redis支持

          在pom.xml中添加

          Xml代碼  收藏代碼
          1. <dependency>  
          2.           <groupId>org.springframework.boot</groupId>  
          3.           <artifactId>spring-boot-starter-redis</artifactId>  
          4.       </dependency>  

           

          2 redis配置

          Java代碼  收藏代碼
          1. @Configuration  
          2. @EnableCaching  
          3. public class RedisCacheConfig {  
          4.     @Bean  
          5.     public CacheManager cacheManager(  
          6.             @SuppressWarnings("rawtypes") RedisTemplate redisTemplate) {  
          7.         return new RedisCacheManager(redisTemplate);  
          8.     }  
          9.   
          10.     @Bean  
          11.     public RedisTemplate<String, String> redisTemplate(  
          12.             RedisConnectionFactory factory) {  
          13.         final StringRedisTemplate template = new StringRedisTemplate(factory);  
          14.         template.setValueSerializer(new Jackson2JsonRedisSerializer<SysUser>(  
          15.                 SysUser.class)); //請注意這里  
          16.   
          17.         return template;  
          18.     }  
          19. }  

           

          3 redis服務器配置

          Properties代碼  收藏代碼
          1. # REDIS (RedisProperties)  
          2. spring.redis.database= # database name  
          3. spring.redis.host=localhost # server host  
          4. spring.redis.password= # server password  
          5. spring.redis.port=6379 # connection port  
          6. spring.redis.pool.max-idle=8 # pool settings ...  
          7. spring.redis.pool.min-idle=0  
          8. spring.redis.pool.max-active=8  
          9. spring.redis.pool.max-wait=-1  
          10. spring.redis.sentinel.master= # name of Redis server  
          11. spring.redis.sentinel.nodes= # comma-separated list of host:port pairs  

           

          4 應用

          Java代碼  收藏代碼
          1. /** 
          2. *此處的dao操作使用的是spring data jpa,使用@Cacheable可以在任意方法上,*比如@Service或者@Controller的方法上 
          3. */  
          4. public interface SysUserRepo1 extends CustomRepository<SysUser, Long> {  
          5.     @Cacheable(value = "usercache")  
          6.     public SysUser findByUsername(String username);  
          7. }  

           

          5 檢驗

          Java代碼  收藏代碼
          1. @Controller  
          2. public class TestController {  
          3.       
          4.       
          5.     @Autowired   
          6.     SysUserRepo1 sysUserRepo1;  
          7.     @RequestMapping("/test")  
          8.     public @ResponseBody String test(){  
          9.   
          10.         final SysUser loaded = sysUserRepo1.findByUsername("wyf");  
          11.         final SysUser cached = sysUserRepo1.findByUsername("wyf");  
          12.           
          13.         return "ok";  
          14.     }   
          15. }  

           

          效果如圖:



           

          posted @ 2015-02-25 10:02 paulwong 閱讀(5281) | 評論 (3)編輯 收藏

          2015年2月份最佳的免費 UI 工具包

          分享到: 
          收藏 +199

          設計師們最喜歡 UI 工具包,這是一種思路拓展的方法,同時可以利用它們來解決各種復雜的項目,同時可用來了解其他設計師的風格。這里我們收集了最近這一個月一些最棒的 UI 工具包,簡介就不再單獨翻譯。

          請觀賞:

          Oh no, not another UI Kit

          A great flat UI kit with tons of elements, “Oh no, not another UI Kit” features simple line icons, straitforward layout and a cheeky sense of humor.

          001

           

          Flat UI Kit

          A flat UI kit based on Twitter Bootstrap. Supplied in PSD format.

          002

           

          Retina UI web kit

          A retina ready UI kit in which dark elements combine with Material Design colors for a powerful effect.

          003

           

          MixKit

          A comprehensive UI kit with tons of pop culture colors.

          004

           

          Hero UI

          Don’t be fooled by the name, this pseudo-flat UI kit is suitable for any number of projects, although it certainly gives off a comic book vibe.

          005

           

          Yosemite UI Kit

          Designed exclusively for Sketch 3 this UI kit is perfect for mocking up Mac app screens.

          007

           

          L Bootstrap

          This kit features over two dozen different PSDs, in the Android Lollipop style.

          008

           

          Basiliq

          This unique UI kit is designed for prototyping, but will also give your finished designs a lovely hand-drawn feel.

          009

           

          Publica UI Kit

          Publica is a comprehensive set of block-style UI elements ideally suited to responsive design.

          010

           

          Mini UI Kit

          Designed for Sketch 3, the dark tones in this UI kit add an extra feel of sophistication.

          011

           

          Clino UI Kit

          Clino UI Kit is a simple set of UI elements in PSD format, that will suit most modern design projects.

          012

           

          Quadruple Ferial

          This UI kit is a perfect blend of minimalism and Google Material Design. It’s ideal for mobile projects.

          013

           

          Clean White

          This sophisticated and sexy UI kit has more than 55 separate elements and is perfect for all manner of high-end design projects.

          014

           

          Eventray

          Eventray is an amazing, comprehensive UI kit that beautifully executes Flat Design.

          015

           

          Number One UI Kit

          This sports-based UI kit includes some great specialist UI elements like league tables, and individual sports icons.

          016

           

          Free Minimal UI Kit

          This UI kit is based on the Twitter Bootstrap framework and is fully responsive.

          017

           

          Gumballz Web UI Kit

          Gumballz Web UI Kit is a quirky, original take on the standard UI kit. Clean minimal design meets beach house colors.

          018

           

          Winter UI Kit

          This UI kit has over 50 elements and icons, all supplied as scaleable vectors in PSD format.

          019

           

          eShop UI Kit

          eShop UI Kit is a vibrant set of UI elements aimed squarely at ecommerce designers.

          020

           

          Free Combination UI Kit

          With bold colors and simple Material Design inspired shapes, this UI kit is perfect for modern dashboard designs.

          021

           

          Free Android UI Kit

          Free Android UI Kit gives you 8 sets of related elements for designing mobile apps.

          022

           

          Clean & Light Gradient UI Kit

          This light dashboard UI kit features line icons and subtle gradients.

          023

           

          Personal Dashboard UI Kit

          A bold and confident dashboard UI.

          024

           

          FooKit Web Footer PSD Kit

          This UI kit is aimed at website footers. It includes social media links, site navigation, and more.

          026

           

          Boring Cards

          Boring cards is a card based UI kit all designed around the golden ratio.

          027

           

          iPhone 6 UI Kit

          The iPhone 6 UI Kit is designed for the latest version of Apple’s smartphone, but it works just as well for Android and Windows.

          028

          via webdesignerdepot

          posted @ 2015-02-24 18:25 paulwong 閱讀(481) | 評論 (0)編輯 收藏

          使用WILDFLY中的分布式緩存INFISHPAN

          項目部署的應用服務器:WILDFLY
          1. 通過http://127.0.0.1:9991/console/App.html#infinispan添加CACHE
            <cache-container name="tickets" default-cache="default" jndi-name="java:jboss/infinispan/tickets">
                   <local-cache name="default" batching="true">
                          <locking isolation="REPEATABLE_READ"/>
                   </local-cache>
            </cache-container>

          2. pom.xml添加依賴包
                    <dependency>
                        <groupId>org.infinispan</groupId>
                        <artifactId>infinispan-core</artifactId>
                        <scope>provided</scope>
                    </dependency>
                    
                    <dependency>
                        <groupId>org.infinispan</groupId>
                        <artifactId>infinispan-client-hotrod</artifactId>
                        <scope>provided</scope>
                    </dependency>

                <dependency>
                    <groupId>org.jgroups</groupId>
                    <artifactId>jgroups</artifactId>
                    <scope>provided</scope>
                </dependency>

                    <dependency>
                        <groupId>org.infinispan</groupId>
                        <artifactId>infinispan-spring</artifactId>
                        <version>6.0.2.Final</version>
                    </dependency>
                    
                    <dependency>
                        <groupId>org.infinispan</groupId>
                        <artifactId>infinispan-jcache</artifactId>
                        <version>6.0.2.Final</version>
                    </dependency>

          3. 添加攔截器,WEB-INF/beans.xml
            <?xml version="1.0"?>
            <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation
            ="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
                <interceptors>
                    <class>org.infinispan.jcache.annotation.CacheResultInterceptor</class>
                    <class>org.infinispan.jcache.annotation.CachePutInterceptor</class>
                    <class>org.infinispan.jcache.annotation.CacheRemoveEntryInterceptor</class>
                    <class>org.infinispan.jcache.annotation.CacheRemoveAllInterceptor</class>
                </interceptors>
            </beans>

          4. 添加項目的全局依賴,WEB-INF/jboss-deployment-structure.xml
            <?xml version="1.0" encoding="UTF-8"?>
            <jboss-deployment-structure>
                <deployment>
                    <dependencies>
                        <module name="org.jboss.xnio" />
                        <module name="org.infinispan" export="true"/>
                        <module name="org.infinispan.commons" export="true"/>
                        <module name="org.infinispan.client.hotrod" export="true"/>
                    </dependencies>
                </deployment>
            </jboss-deployment-structure>

          5. 在CDI BEAN中使用CACHE
            package com.paul.myejb;

            import javax.annotation.Resource;
            import javax.cache.annotation.CacheResult;
            import javax.ejb.Remote;
            import javax.ejb.Stateless;
            import javax.interceptor.Interceptors;

            import org.infinispan.Cache;
            import org.infinispan.manager.EmbeddedCacheManager;
            //import org.springframework.cache.annotation.Cacheable;
            import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;

            /**
             * Session Bean implementation class HelloWorldBean
             
            */
            @Stateless
            //@Local(HelloWorld.class)
            @Remote(HelloWorld.class)
            @Interceptors(SpringBeanAutowiringInterceptor.class)
            //@RolesAllowed({Roles.ADMIN})
            public class HelloWorldBean implements HelloWorld {
                
                @Resource(lookup = "java:jboss/infinispan/tickets")
                private EmbeddedCacheManager container;
                
                
                /**
                 * Default constructor. 
                 
            */
                public HelloWorldBean() {
                }

            //    @Transactional
            //    @Cacheable(value = "books", key = "#name")
                @CacheResult
                public String sayHello(String name) {
                    System.out.println("NO CACHE");
                    String result = "Hello " + name + ", I am HelloWorldBean.";
                    Cache<String, String> cache = this.container.getCache();
                    cache.put(name, result);
                    return result;
                }

            }


          6. 修改modules/system/layers/base/org/infinispan/client/hotrod/main/modules.xml
            <?xml version="1.0" encoding="UTF-8"?>
            <!--
              ~ JBoss, Home of Professional Open Source.
              ~ Copyright 2010, Red Hat, Inc., and individual contributors
              ~ as indicated by the @author tags. See the copyright.txt file in the
              ~ distribution for a full listing of individual contributors.
              ~
              ~ This is free software; you can redistribute it and/or modify it
              ~ under the terms of the GNU Lesser General Public License as
              ~ published by the Free Software Foundation; either version 2.1 of
              ~ the License, or (at your option) any later version.
              ~
              ~ This software is distributed in the hope that it will be useful,
              ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
              ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
              ~ Lesser General Public License for more details.
              ~
              ~ You should have received a copy of the GNU Lesser General Public
              ~ License along with this software; if not, write to the Free
              ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
              ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
              
            -->
            <module xmlns="urn:jboss:module:1.3" name="org.infinispan.client.hotrod">
                <properties>
                    <property name="jboss.api" value="private"/>
                </properties>

                <resources>
                    <resource-root path="infinispan-client-hotrod-6.0.2.Final.jar"/>
                </resources>

                <dependencies>
                    <module name="javax.api"/>
                    <!--下面這一行注釋掉-->
                    <!--<module name="com.google.protobuf"/>-->
                    <module name="org.apache.commons.pool"/>
                    <module name="org.infinispan.commons"/>
                    <module name="org.infinispan.query.dsl"/>
                    <module name="org.jboss.logging"/>
                </dependencies>
            </module>

          以下是SPRING版本
          1. 添加依賴的SPRING BEAN
            <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi
            ="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
                xmlns:cache
            ="http://www.springframework.org/schema/cache"
                xmlns:p
            ="http://www.springframework.org/schema/p"
                xmlns:jee
            ="http://www.springframework.org/schema/jee"
                xsi:schemaLocation
            ="http://www.springframework.org/schema/context
                      http://www.springframework.org/schema/context/spring-context-3.0.xsd
                      http://www.springframework.org/schema/beans
                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                      http://www.springframework.org/schema/cache
                      http://www.springframework.org/schema/cache/spring-cache.xsd
                      http://www.springframework.org/schema/jee 
                      http://www.springframework.org/schema/jee/spring-jee.xsd"
            >

                <cache:annotation-driven />
                
                <bean id="cacheManager"
                      class
            ="org.infinispan.spring.provider.ContainerCacheManagerFactoryBean">
                      <constructor-arg ref="cacheContainer"  />
                </bean>
                
                <jee:jndi-lookup id="cacheContainer" jndi-name="java:jboss/infinispan/tickets" > 
                </jee:jndi-lookup>
                
                <!-- <bean id="cacheContainer"
                      class="com.paul.myejb.common.util.cache.JndiSpringCacheManagerFactoryBean"
                      p:infinispanJNDI="java:jboss/infinispan/tickets" /> 
            -->
                
            </beans>

          2. 使用CACHE
            package com.paul.myejb.spring;

            import org.springframework.beans.factory.annotation.Autowired;
            import org.springframework.cache.CacheManager;
            import org.springframework.cache.annotation.Cacheable;
            import org.springframework.stereotype.Component;

            @Component
            public class MySpringBean {
                
                @Autowired
                private CacheManager cacheManager;
                
                @Cacheable(value = "my-local-cache", key = "#name")
                public String sayHello(String name)
                {
                    System.out.println("MySpringBean NO CACHE");
                    String result = "Hi " + name + ", I am Spring!";
                    org.springframework.cache.Cache springCache = this.cacheManager.getCache("my-local-cache");
                    System.out.println(springCache.get(name) == null ? "null" : springCache.get(name).get());
                    springCache.put(name, result);
                    return result;
                }

            }


          posted @ 2015-02-23 13:40 paulwong 閱讀(1005) | 評論 (0)編輯 收藏

          Infinispan資源

          Infinispan是一個分布式的緩存,由JBOSS開發。支持JSR-107標準。
          使用時最好與SPRING結合,用在DAO層。
          以某方法參數作為KEY,返回的對象作為VALUE保存到緩存中。
          ADD/EDIT/REMOVE方法被執行時則清除所有的緩存。

          Infinispan的運行模式有兩種:
          1、嵌入式
          先啟動一個進程,再在此進程中啟動Infinispan的CACHE MANAGER。
          2、CLIENT/SERVER
          直接運行startserver.sh來啟動。

          兩者區別
          嵌入式:
          1、Infinispan和啟動進程是在同一個進程里,如JBOSS中的Infinispan
          2、要使用Infinispan的CACHE,必須將應用部署到此進程中,如將WAR應用部署到JBOSS中
          3、如有多臺機以此模式運行,則互相可以通訊

          CLIENT/SERVER:
          1、Infinispan單獨一個進程
          2、通過SDK,以MEMCHAED,RHQ等協議訪問CACHE
          3、如有多臺機以此模式運行,互相不可以通訊

          JBOSS中的INFINISPAN肯定是嵌入式,要訪問INFINISPAN的CACHE必須部署到JBOSS才能訪問,沒有遠程模式。

          Infinispan中的CACHE有兩種模式:本地緩存和集群緩存。

          本地緩存是單機版。
          集群緩存是多機網絡版,又分為三種:
          1、分布式:網絡中的每個節點只保存部份緩存條目,所有的節點合起來保存全部緩存條目
          當本機無此條目時,要通過網絡去到別的機器上取
          2、復制式:網絡中的每個節點都保存全部緩存條目,但緩存條目有更新時,所有節點一并更新
          當本機無此條目時,不用到別的節點取,但緩存條目有更新時,所有節點都會執行更新本地緩存操作
          3、無效式:網絡中的每個節點互不通訊,但緩存條目有更新時,節點收到失效通知,各自處理本機的緩存條目

          編程使用方法
          1、通過程序使用,即在代碼中寫cache的存取。
          2、通過注釋使用,這各注釋是通過截面攔截方法方式實現,即如果在緩存中有此緩存條目,則方法不會被執行,直接返回結果。
          又細分兩種:
          通過SPRING實現,通過JAVA EE的CDI實現。

          JBoss 系列三十一:JBoss Data Grid(Infinispan)緩存模式

          JBoss 系列三十二:JBoss Data Grid(Infinispan)緩存模式示例


          infinispan-quickstart


          https://docs.jboss.org/infinispan/5.0/apidocs/org/infinispan/spring/provider/package-summary.html


          Infinispan integrate with spring based application
          http://timtang.me/blog/2012/11/04/infinispan-spring-based-application-integration/


          Java緩存新標準(javax.cache)
          http://www.importnew.com/11723.html

          https://developer.jboss.org/en/infinispan/cn/content?filterID=contentstatus[published]~objecttype~objecttype[document]

          posted @ 2015-02-22 14:03 paulwong 閱讀(518) | 評論 (0)編輯 收藏

          Add Apache Camel and Spring as jboss modules in WildFly

               摘要: by Adrianos Dadis on November 29th, 2013 | Filed in: Enterprise Java Tags: Apache Camel, JBoss WildFly, SpringThese days I am playing with Wildfl...  閱讀全文

          posted @ 2015-02-21 20:13 paulwong 閱讀(685) | 評論 (0)編輯 收藏

          JBoss AS7的classloader機制

               摘要: 術語Deployment部署在AS7中的ear、war等都被稱作為deployment。簡介JBoss AS7(以下簡稱AS7)的class loader機制與JBoss之前的版本有很大的不同。AS7的classloading是在JBoss Modules項目中實現的。與之前的扁平化的雙親委托機制不同,AS7的classloading是基于module的,一個module如果想要“看見...  閱讀全文

          posted @ 2015-02-21 19:35 paulwong 閱讀(1300) | 評論 (0)編輯 收藏

          Undertow新一代JBOSS WEB服務器

          Undertow服務器基礎分析 - 概述


          Undertow服務器基礎分析 - XNIO



          Undertow服務器基礎分析 - Undertow





          posted @ 2015-02-21 17:45 paulwong 閱讀(847) | 評論 (0)編輯 收藏

          僅列出標題
          共115頁: First 上一頁 38 39 40 41 42 43 44 45 46 下一頁 Last 
          主站蜘蛛池模板: 镇康县| 名山县| 马尔康县| 罗甸县| 托克逊县| 遂昌县| 克什克腾旗| 金昌市| 铁岭县| 牟定县| 邢台县| 屏南县| 鹿泉市| 阿鲁科尔沁旗| 聂荣县| 嘉义县| 襄垣县| 白山市| 内丘县| 莱芜市| 昌邑市| 大冶市| 通许县| 万年县| 淳安县| 二连浩特市| 丽水市| 忻州市| 福贡县| 苍山县| 张掖市| 洪江市| 睢宁县| 杭锦后旗| 嘉义县| 繁峙县| 红安县| 甘德县| 洪泽县| 日照市| 毕节市|