<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 88, comments - 3, trackbacks - 0, articles - 0
      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    2012年7月17日

    在Spring cloud config出來(lái)之前, 自己實(shí)現(xiàn)了基于ZK的配置中心, 杜絕了本地properties配置文件, 原理很簡(jiǎn)單, 只是重載了PropertyPlaceholderConfigurer的mergeProperties():

    /**
    * 重載合并屬性實(shí)現(xiàn)
    * 先加載file properties, 然后并入ZK配置中心讀取的properties
    *
    * @return 合并后的屬性集合
    * @throws IOException 異常
    */
    @Override
    protected Properties mergeProperties() throws IOException {
    Properties result = new Properties();
    // 加載父類的配置
    Properties mergeProperties = super.mergeProperties();
    result.putAll(mergeProperties);
    // 加載從zk中讀取到的配置
    Map<String, String> configs = loadZkConfigs();
    result.putAll(configs);
    return result;
    }

    這個(gè)實(shí)現(xiàn)在spring項(xiàng)目里用起來(lái)還是挺順手的, 但是近期部分spring-boot項(xiàng)目里發(fā)現(xiàn)這種placeholder的實(shí)現(xiàn)跟spring boot的@ConfigurationProperties(prefix = "xxx") 不能很好的配合工作,
    也就是屬性沒有被resolve處理, 用@Value的方式確可以讀到, 但是@Value配置起來(lái)如果屬性多的話還是挺繁瑣的, 還是傾向用@ConfigurationProperties的prefix, 于是看了下spring boot的文檔發(fā)現(xiàn)PropertySource order:
       * Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
       * @TestPropertySource annotations on your tests.
       * @SpringBootTest#properties annotation attribute on your tests.
       * Command line arguments.
       * Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
       * ServletConfig init parameters.
       * ServletContext init parameters.
       * JNDI attributes from java:comp/env.
       * Java System properties (System.getProperties()).
       * OS environment variables.
       * A RandomValuePropertySource that only has properties in random.*.
       * Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
       * Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
       * Application properties outside of your packaged jar (application.properties and YAML variants).
       * Application properties packaged inside your jar (application.properties and YAML variants).
       * @PropertySource annotations on your @Configuration classes.
       * Default properties (specified using SpringApplication.setDefaultProperties).
    不難發(fā)現(xiàn)其會(huì)檢查Java system propeties里的屬性, 也就是說, 只要把mergerProperties讀到的屬性寫入Java system props里即可, 看了下源碼, 找到個(gè)切入點(diǎn)

    /**
    * 重載處理屬性實(shí)現(xiàn)
    * 根據(jù)選項(xiàng), 決定是否將合并后的props寫入系統(tǒng)屬性, Spring boot需要
    *
    * @param beanFactoryToProcess
    * @param props 合并后的屬性
    * @throws BeansException
    */
    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
    // 原有邏輯
    super.processProperties(beanFactoryToProcess, props);
    // 寫入到系統(tǒng)屬性
    if (writePropsToSystem) {
    // write all properties to system for spring boot
    Enumeration<?> propertyNames = props.propertyNames();
    while (propertyNames.hasMoreElements()) {
    String propertyName = (String) propertyNames.nextElement();
    String propertyValue = props.getProperty(propertyName);
    System.setProperty(propertyName, propertyValue);
    }
    }
    }
    為避免影響過大, 設(shè)置了個(gè)開關(guān), 是否寫入系統(tǒng)屬性, 如果是spring boot的項(xiàng)目, 就開啟, 這樣對(duì)線上非spring boot項(xiàng)目做到影響最小, 然后spring boot的@ConfigurationProperties完美讀到屬性;

    具體代碼見: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName)
    throws BeansException {
    ConfigurationProperties annotation = AnnotationUtils
    .findAnnotation(bean.getClass(), ConfigurationProperties.class);
    if (annotation != null) {
    postProcessBeforeInitialization(bean, beanName, annotation);
    }
    annotation = this.beans.findFactoryAnnotation(beanName,
    ConfigurationProperties.class);
    if (annotation != null) {
    postProcessBeforeInitialization(bean, beanName, annotation);
    }
    return bean;
    }

    posted @ 2017-12-08 14:13 Milo的海域 閱讀(898) | 評(píng)論 (0)編輯 收藏

    Spring默認(rèn)不允許對(duì)類的變量, 也就是靜態(tài)變量進(jìn)行注入操作, 但是在某些場(chǎng)景比如單元測(cè)試的@AfterClass要訪問注入對(duì)象, 而Junit的這個(gè)方法必須是靜態(tài)的, 也就產(chǎn)生了悖論;

    解決思路有兩個(gè):

    • 思路1: 想辦法對(duì)靜態(tài)變量注入, 也就是繞過Spring只能運(yùn)行非靜態(tài)變量才能注入依賴的壁壘
    • 思路2: 想辦法@AfterClass改造為非靜態(tài)
      • 實(shí)現(xiàn)Junit RunListener, 覆蓋testRunFinished方法, 這里去實(shí)現(xiàn)類似@AfterClass的功能, 這個(gè)方法是非靜態(tài)的
      • 不要用Junit, 改用TestNG, TestNG里的AfterClass是非靜態(tài)的
      • 用Spring的TestExecutionListeners, 實(shí)現(xiàn)個(gè)Listener, 里面也有個(gè)類似非靜態(tài)的AfterClass的實(shí)現(xiàn), 覆蓋實(shí)現(xiàn)就行

    思路2的幾個(gè)方法都可以實(shí)現(xiàn), 但是單元測(cè)試Runner需要用

    @RunWith(Theories.class)

    而且改用TestNG工程浩大, 只能放棄掉這個(gè)思路

    繼續(xù)走思路1, 只能去繞過Spring的依賴注入的static壁壘了, 具體代碼如下:

    @Autowired
    private Destination dfsOperationQueue;
    private static Destination dfsOperationQueueStatic; // static version
    @Autowired
    private MessageQueueAPI messageQueueAPI;
    private static MessageQueueAPI messageQueueAPIStatic; // static version


    @PostConstruct
    public void init() {
    dfsOperationQueueStatic = this.dfsOperationQueue;
    messageQueueAPIStatic = this.messageQueueAPI;
    }

    @AfterClass
    public static void afterClass() {
    MessageVO messageVO = messageQueueAPIStatic.removeDestination(dfsOperationQueueStatic);
    System.out.println(messageVO);
    }

    其實(shí)就是用了@PostConstruct 來(lái)個(gè)偷梁換柱而已, 多聲明個(gè)靜態(tài)成員指向非靜態(tài)對(duì)象, 兩者其實(shí)是一個(gè)對(duì)象

    posted @ 2017-04-15 10:32 Milo的海域 閱讀(592) | 評(píng)論 (0)編輯 收藏

    知道activemq現(xiàn)在已經(jīng)支持了rest api, 但是官方對(duì)這部分的介紹一筆帶過 (http://activemq.apache.org/rest.html),


    通過google居然也沒搜到一些有用的, 比如像刪除一個(gè)destination, 都是問的多,然后沒下文. 于是花了一些心思研究了一下:


    首先通過rest api獲取當(dāng)前版本所有已支持的協(xié)議

        http://172.30.43.206:8161/api/jolokia/list


    然后根據(jù)json輸出關(guān)于removeTopic, removeQueue的mbean實(shí)現(xiàn)通過rest api刪除destination的方法, 注意到用GET請(qǐng)求而不是POST,不然會(huì)報(bào)錯(cuò) (官網(wǎng)的例子里用的wget給的靈感, 開始用了POST老報(bào)錯(cuò))


    import org.apache.activemq.command.ActiveMQQueue;
    import org.apache.activemq.command.ActiveMQTopic;
    import org.apache.http.auth.AuthScope;
    import org.apache.http.auth.UsernamePasswordCredentials;
    import org.apache.http.impl.client.BasicCredentialsProvider;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.springframework.http.HttpEntity;
    import org.springframework.http.HttpHeaders;
    import org.springframework.http.HttpMethod;
    import org.springframework.http.MediaType;
    import org.springframework.http.ResponseEntity;
    import org.springframework.http.client.ClientHttpRequestFactory;
    import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
    import org.springframework.web.client.RestTemplate;

    import javax.jms.Destination;
    import javax.jms.JMSException;
    import java.util.Arrays;


    public class MessageQueueAdmin {
        
    private static final RestTemplate restTemplate = getRestTemplate("admin""admin");

        
    private static String brokerHost = "172.30.43.206";
        
    private static String adminConsolePort = "8161";
        
    private static String protocol = "http";

        
    public static void removeDestination(Destination destination) throws JMSException {
            String destName, destType;
            
    if (destination instanceof ActiveMQQueue) {
                destName 
    = ((ActiveMQQueue) destination).getQueueName();
                destType 
    = "Queue";
            } 
    else {
                destName 
    = ((ActiveMQTopic) destination).getTopicName();
                destType 
    = "Topic";
            }

            
    // build urls
            String url = String.format("%s://%s:%s/api/jolokia/exec/org.apache.activemq:" +
                    
    "brokerName=localhost,type=Broker/remove%s/%s", protocol, brokerHost, adminConsolePort, destType, destName);
            System.out.println(url);
            
    // do operation
            HttpHeaders headers = new HttpHeaders();
            headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
            HttpEntity
    <String> entity = new HttpEntity<String>("parameters", headers);
            ResponseEntity response 
    = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
            System.out.println(response.getBody());
        }

        
    public static void main(String[] args) throws JMSException {
            ActiveMQTopic topic 
    = new ActiveMQTopic("test-activemq-topic");
            removeDestination(topic);
        }


        
    private static RestTemplate getRestTemplate(String user, String password) {
            DefaultHttpClient httpClient 
    = new DefaultHttpClient();
            BasicCredentialsProvider credentialsProvider 
    = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, 
    new UsernamePasswordCredentials(user, password));
            httpClient.setCredentialsProvider(credentialsProvider);
            ClientHttpRequestFactory rf 
    = new HttpComponentsClientHttpRequestFactory(httpClient);

            
    return new RestTemplate(rf);
        }
    }

    其他的請(qǐng)求,應(yīng)該都是類似jolokia的exec get request的格式:


    https://jolokia.org/reference/html/protocol.html#exec


    <base url>/exec/<mbean name>/<operation name>/<arg1>/<arg2>/.

    posted @ 2016-10-22 17:31 Milo的海域 閱讀(1438) | 評(píng)論 (0)編輯 收藏

    用Spring JMS 的JmsTemplate從消息隊(duì)列消費(fèi)消息時(shí)發(fā)現(xiàn),使用了CLIENT_ACKNOWLEDGE模式,消息返回后總是自動(dòng)被ack,也就是被broker "Dequeued"

        protected Message doReceive(Session session, MessageConsumer consumer) throws JMSException {
            
    try {
                
    // Use transaction timeout (if available).
                long timeout = getReceiveTimeout();
                JmsResourceHolder resourceHolder 
    =
                        (JmsResourceHolder) TransactionSynchronizationManager.getResource(getConnectionFactory());
                
    if (resourceHolder != null && resourceHolder.hasTimeout()) {
                    timeout 
    = Math.min(timeout, resourceHolder.getTimeToLiveInMillis());
                }
                Message message 
    = doReceive(consumer, timeout);
                
    if (session.getTransacted()) {
                    
    // Commit necessary - but avoid commit call within a JTA transaction.
                    if (isSessionLocallyTransacted(session)) {
                        
    // Transacted session created by this template -> commit.
                        JmsUtils.commitIfNecessary(session);
                    }
                }
                
    else if (isClientAcknowledge(session)) {
                    
    // Manually acknowledge message, if any.
                    if (message != null) {
                        message.acknowledge();
                    }
                }
                
    return message;
            }
            
    finally {
                JmsUtils.closeMessageConsumer(consumer);
            }
        }

    但是使用異步listener 就不會(huì)出現(xiàn)這個(gè)情況,搜了下google,發(fā)現(xiàn)果然存在這個(gè)問題

         https://jira.spring.io/browse/SPR-12995
         https://jira.spring.io/browse/SPR-13255
         http://louisling.iteye.com/blog/241073

    同步方式拉取消息,暫時(shí)沒找到好的封裝,只能暫時(shí)用這。或者盡量用listener, 這個(gè)問題暫時(shí)標(biāo)記下,或者誰(shuí)有更好的解決方案可以comment我

    posted @ 2016-10-12 16:32 Milo的海域 閱讀(1538) | 評(píng)論 (0)編輯 收藏

    默認(rèn)的配置有時(shí)候點(diǎn)不亮顯示器,且分辨率很低,通過tvservice工具不斷調(diào)試,發(fā)現(xiàn)下面的參數(shù)可以完美匹配了
    修改 /boot/config.txt的下列參數(shù)

    disable_overscan=1
    hdmi_force_hotplug
    =1
    hdmi_group
    =1
    hdmi_mode
    =16
    hdmi_drive
    =2
    config_hdmi_boost
    =4
    dtparam
    =audio=on

    posted @ 2016-06-15 09:32 Milo的海域 閱讀(223) | 評(píng)論 (0)編輯 收藏

    http://stackoverflow.com/questions/3294423/spring-classpath-prefix-difference



      

    SIMPLE DEFINITION

    The classpath*:conf/appContext.xml simply means that all appContext.xml files under conf folders in all your jars on the classpath will be picked up and joined into one big application context.

    In contrast
    , classpath:conf/appContext.xml will load only one such file the first one found on your classpath.


    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:*.properties</value>
    <value>classpath*:*.properties</value>
    </list>
    </property>
    </bean>

    posted @ 2016-05-26 14:14 Milo的海域 閱讀(769) | 評(píng)論 (0)編輯 收藏

    1. IDEA_JDK (or IDEA_JDK_64) environment variable
    2. jre/ (or jre64/) directory in IDEA home
    3. registry
    4. JDK_HOME environment variable
    5. JAVA_HOME environment variable

    posted @ 2016-05-16 08:49 Milo的海域 閱讀(163) | 評(píng)論 (0)編輯 收藏

    java里如何修改console的歷史輸出信息呢?如果是當(dāng)前行的修改可以簡(jiǎn)單想到"\r"的方案,但是如果要修改上一行呢? google了下原來(lái)還是有方法的,需要用到ansi的control sequences
    ANSI code

    用java寫了個(gè)簡(jiǎn)單的例子,例子就是把曾經(jīng)的output修改為其他字符串并恢復(fù)之后的打印,代碼里加了sleep,主要方便理解各種控制序列的含義
            //print some test messages
            System.out.println("1");
            Thread.sleep(
    1000);
            System.out.println(
    "22");
            Thread.sleep(
    1000);
            System.out.println(
    "333");
            Thread.sleep(
    1000);
            System.out.println(
    "4444");
            Thread.sleep(
    1000);

            
    /**
             * modify "333" to "-"
             
    */
            
    // Move up two lines
            int count = 2;
            System.out.print(String.format(
    "\033[%dA", count));
            Thread.sleep(
    1000);
            
    // Erase current line content
            System.out.print("\033[2K");
            Thread.sleep(
    1000);
            
    // update with new content
            System.out.print("-");
            Thread.sleep(
    1000);
            
    // Move down two lines
            System.out.print(String.format("\033[%dB", count));
            Thread.sleep(
    1000);
            
    // Move cursor to left beginning
            System.out.print(String.format("\033[D", count));
            
    // continue print others
            Thread.sleep(1000);
            System.out.println(
    "55555");
            Thread.sleep(
    1000);

    posted @ 2016-04-21 17:06 Milo的海域 閱讀(413) | 評(píng)論 (0)編輯 收藏

    1. zookeeper basic/fast paxsos 的形象表述 https://www.douban.com/note/208430424/
    2. 詳細(xì)介紹 http://blog.csdn.net/xhh198781/article/details/10949697

    posted @ 2016-03-31 14:06 Milo的海域 閱讀(185) | 評(píng)論 (0)編輯 收藏

    server.compression.enabled=true 
    server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain
    server.compression.min-response-size=4096
    第一個(gè)參數(shù)打開壓縮開關(guān),第二個(gè)參數(shù)添加json reponse(尤其是為rest api),第三個(gè)參數(shù)是根據(jù)reponse的大小設(shè)置啟用壓縮的最小值(默認(rèn)是2K,自己根據(jù)實(shí)際情況調(diào)整)

    參考
    http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#how-to-enable-http-response-compression

    posted @ 2016-03-29 11:50 Milo的海域 閱讀(1901) | 評(píng)論 (0)編輯 收藏

    介紹centos7如何安裝3.0以上的新版本mongodb
    https://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/

    posted @ 2016-03-23 10:14 Milo的海域 閱讀(186) | 評(píng)論 (0)編輯 收藏

    1. 默認(rèn)的3個(gè)classloader: BootstrapClassloader (Native實(shí)現(xiàn)), ExtClassloader, AppClassloader (Java實(shí)現(xiàn))
    2. 3個(gè)加載器并不是真正的父子繼承關(guān)系,而是邏輯上的,JVM啟動(dòng)先創(chuàng)建ExtClassloader instance,然后構(gòu)造AppClassloader的時(shí)候傳入ExtClassloader實(shí)例作為parent
            Launcher.ExtClassLoader extcl;
            
    try {
                extcl 
    = Launcher.ExtClassLoader.getExtClassLoader();
            } 
    catch (IOException var10) {
                
    throw new InternalError("Could not create extension class loader", var10);
            }

            
    try {
                
    this.loader = Launcher.AppClassLoader.getAppClassLoader(extcl);
            } 
    catch (IOException var9) {
                
    throw new InternalError("Could not create application class loader", var9);
            }

    關(guān)于雙親委派原理: 在加載類的時(shí)候,會(huì)看看parent有沒有設(shè)定,如果設(shè)定了 就調(diào)用parent.loadClass方法,如果沒設(shè)定(==null)也就是parent應(yīng)該是BootstrapClassloader, 會(huì)調(diào)用native的findBootstrapClass來(lái)加載類,代碼:
                    try {
                        
    if(this.parent != null) {
                            c 
    = this.parent.loadClass(name, false);
                        } 
    else {
                            c 
    = this.findBootstrapClassOrNull(name);
                        }
                    } 
    catch (ClassNotFoundException var10) {
                        ;
                    }

    目的是按照一定優(yōu)先級(jí)別裝載系統(tǒng)的lib,系統(tǒng)ext目錄的lib,以及classpath的lib,防止系統(tǒng)的默認(rèn)行為或者類的實(shí)現(xiàn)被修改。

    3. java 類的動(dòng)態(tài)加載
    Java內(nèi)置的ClassLoader總會(huì)在加載一個(gè)Class之前檢查這個(gè)Class是否已經(jīng)被加載過,已經(jīng)被加載過的Class不會(huì)加載第二次。因此要想重新加載Class,我們需要實(shí)現(xiàn)自己的ClassLoader。
    另外一個(gè)問題是,每個(gè)被加載的Class都需要被鏈接(link),這是通過執(zhí)行ClassLoader.resolve()來(lái)實(shí)現(xiàn)的,這個(gè)方法是 final的,因此無(wú)法重寫。Resove()方法不允許一個(gè)ClassLoader實(shí)例link一個(gè)Class兩次,因此,當(dāng)你需要重新加載一個(gè) Class的時(shí)候,你需要重新New一個(gè)你自己的ClassLoader實(shí)例。

    posted @ 2016-03-16 15:40 Milo的海域 閱讀(315) | 評(píng)論 (0)編輯 收藏


    maven-shade-plugin 用來(lái)打可執(zhí)行jar包, 可以把所有依賴的三方庫(kù)都包括進(jìn)來(lái)
    exec-maven-plugin 可以執(zhí)行外部命令, 在項(xiàng)目中對(duì)python代碼進(jìn)行編譯, 配合maven-assembly-plugin來(lái)生成package
    maven-assembly-plugin 用來(lái)構(gòu)建項(xiàng)目發(fā)行包, 要配合xml配置文件來(lái)組織包的結(jié)構(gòu),基本思路是從build環(huán)境copy到outputDirectory
    license-maven-plugin 用來(lái)生成項(xiàng)目用到的3方庫(kù)的版權(quán)匯總 或者其他的一些用法
    maven-dependency-plugin 用來(lái)生成項(xiàng)目庫(kù)之間的依賴關(guān)系
    appassembler-maven-plugin 可以為項(xiàng)目生成優(yōu)雅的啟動(dòng)腳本 支持linux/win
    rpm-maven-plugin 用來(lái)為項(xiàng)目構(gòu)建rpm安裝包
    maven-compiler-plugin 指定項(xiàng)目的jdk的編譯兼容版本以及encoding類別

    posted @ 2016-01-26 11:41 Milo的海域 閱讀(263) | 評(píng)論 (0)編輯 收藏

    快捷鍵migrating
    定位選中字符串下個(gè)匹配的位置
    eclipse: ctrl + k
    idea: ctrl + F3       

    eclipse: ctrl + q
    idea: ctrl + shift + backspace
    回到上一次編輯的位置

    持續(xù)更新

    posted @ 2015-11-25 16:46 Milo的海域 閱讀(123) | 評(píng)論 (0)編輯 收藏

    發(fā)現(xiàn)一個(gè)不錯(cuò)的介紹shell中冒號(hào)的用法的文章
    http://codingstandards.iteye.com/blog/1160298

    posted @ 2015-11-09 15:11 Milo的海域 閱讀(244) | 評(píng)論 (0)編輯 收藏

    項(xiàng)目用mvn exec:exec指令來(lái)啟動(dòng)server, 工作中需要調(diào)式server初始化的過程, 很容易想到mvnDebug, 但是發(fā)現(xiàn)設(shè)置的斷點(diǎn)都沒有hit, 反復(fù)調(diào)式多次都是如此,折騰了1個(gè)多小時(shí), 突然看到stackoverflow 上有人說exec:exec是獨(dú)立進(jìn)程模式, mvnDebug的一些debug選項(xiàng)都被append到了父進(jìn)程了. idea設(shè)置斷點(diǎn)就然并卵了.

    知道了問題所在解決就容易了, 只要修改pom.xml, 然后直接mvn exec:exec就能正常調(diào)式了
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <version>${mvnexec.version}</version>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>exec</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <configuration>
                                <includeProjectDependencies>true</includeProjectDependencies>
                                <executable>java</executable>
                                <workingDirectory>${basedir}/config/sim</workingDirectory>
                                <classpathScope>runtime</classpathScope>
                                <arguments>
                                    <argument>-agentlib:jdwp
    =transport=dt_socket,server=y,suspend=y,address=4000</argument>
                                    <argument>-classpath</argument>
                                    <classpath/>
                                    <argument>com.ymiao.Main</argument>
                                    <argument>server</argument>
                                    <argument>${basedir}/config/sim/sim.yml</argument>
                                </arguments>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>

    總結(jié)就是exec:exec是要獨(dú)立一個(gè)新進(jìn)程來(lái)執(zhí)行程序的, exec:java就相反, 其實(shí)用mvnDebug + exec:java也是理論可行的

    posted @ 2015-10-21 17:12 Milo的海域 閱讀(832) | 評(píng)論 (0)編輯 收藏

    After Centos 7.1 tobe installed on my t400, my wireless link "Intel 5100 AGN" cannot be managed by NetworkManager, which show in "PCI unknown" state.

    Googled many pages, most of them introduced how to scan wifi links by command line tool "iw", i tried all steps supplied by the pages but was blocked at the last step to get dynamical ipaddress by dhclient command "sudo dhclient wlp3s0 -v". The dhclient always complain "NO DHCPOFFERS received." (I doubted there should be some tricky to play with dhclient but which i am not faimiar with.. sad.. )

    But i think there would be some extending tool for NetworkManager to manager wifi, then i google "NetworkManager wifi", i got "NetwrokManager-wifi plugin" from link https://www.centos.org/forums/viewtopic.php?f=47&t=52810

    After following steps , i finally make wifi work well on centos 7.1

    • yum install NetworkManager-wifi
    • reboot machine (i tried logout and login, not work) 

    Problem is NetworkManager-wifi is not installed by default on centos 7.1, (would it be my mistake when install OS? strange..)

    posted @ 2015-09-17 10:41 Milo的海域 閱讀(391) | 評(píng)論 (1)編輯 收藏

    http://onlywei.github.io/explain-git-with-d3

    posted @ 2015-09-09 15:57 Milo的海域 閱讀(244) | 評(píng)論 (0)編輯 收藏

    項(xiàng)目中要用到MBean,于是快速體驗(yàn)下,體驗(yàn)過程中發(fā)現(xiàn)2個(gè)問題:

    1. 自定義的Mbean的普通method能在jconsole的Mbeans里顯示出來(lái),但是涉及到geters/seters就無(wú)法顯示了
    2. 如果MBean注冊(cè)到下面形式創(chuàng)建的MBeanServer在Jconsole上無(wú)法顯示的
      MBeanServer server = MBeanServerFactory.createMBeanServer();
      但是如果注冊(cè)到下面的形式創(chuàng)建的Server在Jconsole上是可以顯示MBean的
      MBeanServer server = ManagementFactory.getPlatformMBeanServer();       

    stackoverflow上也有人發(fā)現(xiàn)這個(gè)問題

        http://stackoverflow.com/questions/7424009/mbeans-registered-to-mbean-server-not-showing-up-in-jconsole

    posted @ 2015-09-08 10:53 Milo的海域 閱讀(517) | 評(píng)論 (0)編輯 收藏

    http://www.ourd3js.com/wordpress/

    posted @ 2015-08-26 11:22 Milo的海域 閱讀(253) | 評(píng)論 (0)編輯 收藏

    Two compile issues i got:

    One issue is:
        uuid_gen_unix.c: In function 'axutil_uuid_gen_v1':uuid_gen_unix.c:62:20: error: variable 'tv' set but not used [-Werror=unused-but-set-variable]     struct timeval tv;                    ^cc1: all warnings being treated as errors    


    Solution is remove "-Werror" in all configure scripts
    find -type f -name configure -exec sed -i '/CFLAGS/s/-Werror//g' {} \;
    Another issue is:
    /usr/bin/ld: test.o: undefined reference to symbol 'axiom_xml_reader_free'
    /usr/local/axis2c/lib/libaxis2_parser.so
    .0: error adding symbols: DSO missing from command line
    collect2: error: ld returned 
    1 exit status
    make
    [4]: *** [test] Error 1
    make
    [4]: Leaving directory `/home/miaoyachun/softwares/test/axis2c-src-1.6.0/neethi/test'

    As suggested in https://code.google.com/p/staff/issues/detail?id=198, the solution is disable neethi/test in following files:
    • neethi/configure, remove all "test/Makefile"
    • neethi/Makefile.am, update "SUBDIRS = src test" with "SUBDIRS = src"
    • neethi/Makefile.in, update "SUBDIRS = src test" with "SUBDIRS = src"

    Finally, you could run "make; sudo make install"" successfully. Last thing should be paid attention to is you may need copy all head files of neethi/include into /usr/local/axis2c/include/axis2-1.6.0/ which needed when you compile customized web service.

    Enjoining it!!

    posted @ 2015-08-21 11:00 Milo的海域 閱讀(531) | 評(píng)論 (0)編輯 收藏

    http://axis.apache.org/axis2/c/core/docs/axis2c_manual.html#client_api 的hello.c client 編譯命令在我的ubuntu 12.04s上總是報(bào)錯(cuò)
    gcc -o hello -I$AXIS2C_HOME/include/axis2-1.6.0/ -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -laxis2_engine -lpthread -laxis2_http_sender -laxis2_http_receiver -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib hello.c
    /tmp/ccCYikFh.o: In function `main':
    hello.c:(.text+0x57): undefined reference to `axutil_env_create_all'
    hello.c:(.text+0x68): undefined reference to `axis2_options_create'
    hello.c:(.text+0x93): undefined reference to `axutil_strcmp'
    hello.c:(.text+0xeb): undefined reference to `axis2_endpoint_ref_create'
    hello.c:(.text+0x102): undefined reference to `axis2_options_set_to'
    hello.c:(.text+0x13d): undefined reference to `axis2_svc_client_create'
    hello.c:(.text+0x168): undefined reference to `axutil_error_get_message'
    hello.c:(.text+0x193): undefined reference to `axutil_log_impl_log_error'
    hello.c:(.text+0x1b1): undefined reference to `axis2_svc_client_set_options'
    hello.c:(.text+0x1d6): undefined reference to `axis2_svc_client_send_receive'
    hello.c:(.text+0x21d): undefined reference to `axiom_node_free_tree'
    hello.c:(.text+0x238): undefined reference to `axutil_error_get_message'
    hello.c:(.text+0x266): undefined reference to `axutil_log_impl_log_error'
    hello.c:(.text+0x28d): undefined reference to `axis2_svc_client_free'
    hello.c:(.text+0x2a8): undefined reference to `axutil_env_free'
    /tmp/ccCYikFh.o: In function `build_om_request':
    hello.c:(.text+0x2ed): undefined reference to `axiom_element_create'
    hello.c:(.text+0x307): undefined reference to `axiom_element_set_text'
    /tmp/ccCYikFh.o: In function `process_om_response':
    hello.c:(.text+0x337): undefined reference to `axiom_node_get_first_child'
    hello.c:(.text+0x351): undefined reference to `axiom_node_get_node_type'
    hello.c:(.text+0x367): undefined reference to `axiom_node_get_data_element'
    hello.c:(.text+0x381): undefined reference to `axiom_text_get_value'
    hello.c:(.text+0x396): undefined reference to `axiom_text_get_value'
    collect2: error: ld returned 
    1 exit status
    仔細(xì)檢查了gcc命令,頭文件,庫(kù)文件的路徑都是對(duì)的,最后跟同事討論才發(fā)現(xiàn)hello.c的位置的問題。。如果hello.c的位置放到了依賴庫(kù)的右面 就會(huì)報(bào)類似錯(cuò)誤。但是官方的例子應(yīng)該是測(cè)試過的,怎么會(huì)有這個(gè)問題呢? 難道我的ubuntu 12.04的gcc比較嚴(yán)格?

    修正后的gcc命令如下
    gcc -o hello hello.c  -I$AXIS2C_HOME/include/axis2-1.6.0/ -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -laxis2_engine -lpthread -laxis2_http_sender -laxis2_http_receiver -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib

    posted @ 2015-08-18 17:59 Milo的海域 閱讀(346) | 評(píng)論 (0)編輯 收藏

    ubuntu 12.04s每次修改limit.conf文件后,要想讓所有的后繼ssession都能看到修改,一般要么重啟系統(tǒng),要么relogin系統(tǒng)。下面介紹一個(gè)不退出terminal就讓修改立刻生效的方式
    1. 修改/etc/pam.d/sudo,添加下面行到文件末尾
    session    required   pam_limits.so
    2. 修改 /etc/security/limits.conf, 比如
    root soft nofile 65535
    root hard nofile 
    65535
    3. 執(zhí)行sudo -i -u root 模擬登錄初始化

    另外發(fā)現(xiàn)centos 6系統(tǒng)/etc/pam.d/sudo已經(jīng)默認(rèn)enable pam_limits.so了,直接2,3就可以了。

    當(dāng)然如果用ssh重新登錄下可能來(lái)的更快。。因?yàn)?etc/pam.d/sshd默認(rèn)enable了pam_limits.so, 多輸入個(gè)密碼而已

    posted @ 2015-08-13 17:58 Milo的海域 閱讀(4576) | 評(píng)論 (0)編輯 收藏

    ss(shadowsocks) 是基于socks5的,但是android studio sdk manager只支持http代理,導(dǎo)致android studio無(wú)法更新sdk tools,解決方法就是polipo,可以將socks5轉(zhuǎn)換為http代理
    具體方法見
    https://github.com/shadowsocks/shadowsocks/wiki/Convert-Shadowsocks-into-an-HTTP-proxy

    posted @ 2015-06-28 21:50 Milo的海域 閱讀(1335) | 評(píng)論 (0)編輯 收藏

    ubuntu上ibus經(jīng)常出現(xiàn)不能輸入中文的情況,用下面命令可以臨時(shí)解決問題
    ibus-daemon -r &

    posted @ 2015-06-17 13:45 Milo的海域 閱讀(517) | 評(píng)論 (0)編輯 收藏

    從jdk7最開始的release version (http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html)的notes里看到

    Area: HotSpot
    Synopsis: In JDK 7, interned strings are no longer allocated in the permanent generation of the Java heap, but are instead allocated in the main part of the Java heap (known as the young and old generations), along with the other objects created by the application. This change will result in more data residing in the main Java heap, and less data in the permanent generation, and thus may require heap sizes to be adjusted. Most applications will see only relatively small differences in heap usage due to this change, but larger applications that load many classes or make heavy use of the String.intern() method will see more significant differences.
    RFE: 6962931

    posted @ 2015-05-06 17:35 Milo的海域 閱讀(1858) | 評(píng)論 (0)編輯 收藏

    今天有同事問為什么ubuntu上啟動(dòng)jenkins失敗,我記得之前玩的時(shí)候并沒有出現(xiàn)這種情況,于是跟蹤了下,最終錯(cuò)誤信息是:

    daemon: fatal: refusing to execute unsafe program: /usr/bin/java (/opt is group and world writable)

    根本原因是機(jī)器裝了多個(gè)版本的jdk, jdk所在的/opt父目錄的權(quán)限放的比較大,按照daemon要求的限制到755
    chmod -R 755 /opt

    問題就解決了。

    其實(shí)這個(gè)場(chǎng)景還是蠻常見的,遇到的人應(yīng)該挺多的

    posted @ 2015-02-28 16:51 Milo的海域 閱讀(538) | 評(píng)論 (0)編輯 收藏

    latency = client send request time + network trans time (->)+ server receive request time+ reponse time + server send reponse time+ network trans time (<-)+ client receive reponse time

    latency = first byte out, last byte in time

    posted @ 2014-07-01 14:10 Milo的海域 閱讀(565) | 評(píng)論 (0)編輯 收藏

    以前用centos的chkconfig來(lái)管理系統(tǒng)服務(wù),而ubuntu上是沒有這個(gè)工具的,google上提到一個(gè)替代品sysv-rc-conf, apt-get install下就可以直接用了,有個(gè)text console可以使用

    posted @ 2013-12-24 14:54 Milo的海域 閱讀(5276) | 評(píng)論 (0)編輯 收藏

    Java程序的memory leak分析也可以用valgrind, 尤其是JNI程序尤其有用:
    valgrind --error-limit=no --trace-children=yes --smc-check=all --leak-check=full JAVA_CMD

    特意寫了個(gè)有l(wèi)eak的jni函數(shù),用valgrind成功檢查出來(lái)了
    ==31915== 100 bytes in 1 blocks are definitely lost in loss record 447 of 653
    ==31915==    at 0x402CE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
    ==31915==    by 0x60424F9: Java_MyJNI_hello (MyJNI.c:16)

    在老版本valgrind(3.5.0) enable了--trace-children選項(xiàng)后可能出現(xiàn)錯(cuò)誤:
     Error occurred during initialization of VM    
    Unknown x64 processor: SSE2 not supported

    升級(jí)到最新版可以解決這個(gè)問題,升級(jí)方法:下載src包 解壓后執(zhí)行 ./configure; make; make install

    posted @ 2013-12-06 10:26 Milo的海域 閱讀(1000) | 評(píng)論 (0)編輯 收藏

    maven項(xiàng)目中有很多本地三方依賴,但是一個(gè)一個(gè)加入dependency + system scope又很麻煩,又貌似沒有搜索到通配符的成功案例,但是從stackoverflow上看到一個(gè)插件addjars-maven-plugin, 可以很好解決這類需求:
        <build>
            
    <plugins>
                
    <plugin>
                    
    <groupId>com.googlecode.addjars-maven-plugin</groupId>
                    
    <artifactId>addjars-maven-plugin</artifactId>
                    
    <version>1.0.2</version>
                    
    <executions>
                        
    <execution>
                            
    <goals>
                                
    <goal>add-jars</goal>
                            
    </goals>
                            
    <configuration>
                                
    <resources>
                                    
    <resource>
                                        
    <directory>${basedir}/../lib</directory>
                                    
    </resource>
                                
    </resources>
                            
    </configuration>
                        
    </execution>
                    
    </executions>
                
    </plugin>
                
    <plugin>
                    
    <groupId>org.apache.maven.plugins</groupId>
                    
    <artifactId>maven-assembly-plugin</artifactId>
                    
    <version>${maven.assembly.version}</version>
                    
    <configuration>
                        
    <descriptorRefs>
                            
    <descriptorRef>jar-with-dependencies</descriptorRef>
                        
    </descriptorRefs>
                        
    <appendAssemblyId>false</appendAssemblyId>
                    
    </configuration>
                    
    <executions>
                        
    <execution>
                            
    <phase>package</phase>
                            
    <goals>
                                
    <goal>single</goal>
                            
    </goals>
                        
    </execution>
                    
    </executions>
                
    </plugin>
            
    </plugins>
        
    </build>

    把項(xiàng)目中依賴的三方j(luò)ars全放到lib目錄里,就全部會(huì)打包到release jar里了

    posted @ 2013-10-30 14:03 Milo的海域 閱讀(1933) | 評(píng)論 (0)編輯 收藏

    #include <stdio.h>
    #include 
    <stdlib.h>
    #include 
    <string.h>
    #include 
    <arpa/inet.h>
    #include 
    <inttypes.h>

    uint64_t htonll(uint64_t val) {
        
    return (((uint64_t) htonl(val)) << 32+ htonl(val >> 32);
    }

    uint64_t ntohll(uint64_t val) {
        
    return (((uint64_t) ntohl(val)) << 32+ ntohl(val >> 32);
    }
    int main() {
        uint64_t hll 
    = 0x1122334455667788;
        printf(
    "uint64: %"PRIu64"\n", hll);
        printf(
    "0x%"PRIX64"\n", hll);
        printf(
    "htonll(hll) = 0x%"PRIX64"\n", htonll(hll));
        printf(
    "ntohll(htonll(hll)) = 0x%"PRIX64"\n", ntohll(htonll(hll)));
        printf(
    "ntohll(hll) = 0x%"PRIX64"\n", ntohll(hll)); // no change
        return 1;
    }

    big endian(network byte order), little endian (host byte order in intel arch)

    posted @ 2013-07-23 16:42 Milo的海域 閱讀(3310) | 評(píng)論 (0)編輯 收藏

    用jd-eclipse 插件來(lái)反編譯java class文件的輸出還是挺nice的,雖然閱讀方便了 但是對(duì)debug確造成一定的困擾,主要問題是line number的不match.
    Google了下遇到類似問題的真不少。最終找到了解決方案:
    http://sourceforge.net/projects/realignmentjd/files/
    -----------------

    1. Download JD-Eclipse and JD-GUI - http://java.decompiler.free.fr/ and install.
    2. Put a file realignment.jd.ide.eclipse_1.0.2.jar in eclipse/plugins directory.
        To use Realignment feature it is necessary to open the menu Preferences/General/Editors/File Associations and to select "*.class" file type and to choose "Realignment for JD Class File Editor" for Associated editors.
        Another possibility is the batch realignment after processing JD-GUI. To work properly you must to switch on the property "Display line numbers" in Help/Preferences of JD-GUI.
        To use this feature it is necessary to open the menu Preferences/Java/Decompiler/Batch Realignment and click button "Open dialog". Existing limitation: the realignment is performed only for the methods.
        To work properly it is necessary that the property "Display line numbers" in menu "Preferences/Java/Decompiler" was active.


    JD-Eclipse插件 + realignment 補(bǔ)丁讓優(yōu)雅的debug class 文件成為可能。

    如果只是為了閱讀class代碼,建議不要用realignment 補(bǔ)丁,這樣會(huì)降低代碼的可讀性(會(huì)多出大量的空行)
     

    posted @ 2013-02-22 15:01 Milo的海域 閱讀(2051) | 評(píng)論 (0)編輯 收藏


    sudo dpkg -l \*erlang\*
    Desired
    =Unknown/Install/Remove/Purge/Hold
    | Status
    =Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    |/ Err?
    =(none)/Reinst-required (Status,Err: uppercase=bad)
    ||/ Name                          Version                       Description
    +++-
    =============================-=============================-==========================================================================
    ii  erlang                        
    1:14.b.4-dfsg-1ubuntu1        Concurrent, real-time, distributed functional language
    un  erlang-abi-
    13.a               <none>                        (no description available)
    ii  erlang-appmon                 
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application monitor
    ii  erlang-asn1                   
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP modules for ASN.1 support
    rc  erlang-base                   
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP virtual machine and base applications
    ii  erlang-base-hipe              
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP HiPE enabled virtual machine and base applications
    ii  erlang-common-test            
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application for automated testing
    ii  erlang-corba                  
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP applications for CORBA support
    ii  erlang-crypto                 
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP cryptographic modules
    ii  erlang-debugger               
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application for debugging and testing
    ii  erlang-dev                    
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP development libraries and headers
    ii  erlang-dialyzer               
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP discrepancy analyzer application
    ii  erlang-diameter               
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP implementation of RFC 3588 protocol
    ii  erlang-doc                    
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP HTML/PDF documentation
    un  erlang-doc-html               <none>                        (no description available)
    ii  erlang-docbuilder             
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application for building HTML documentation
    ii  erlang-edoc                   
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP module for generating documentation
    ii  erlang-erl-docgen             
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP documentation stylesheets
    ii  erlang-et                     
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP event tracer application
    ii  erlang-eunit                  
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP module for unit testing
    ii  erlang-examples               
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application examples
    ii  erlang-gs                     
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP graphics system
    ii  erlang-ic                     
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP IDL compiler
    ii  erlang-ic-java                
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP IDL compiler (Java classes)
    ii  erlang-inets                  
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP Internet clients and servers
    ii  erlang-inviso                 
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP trace tool
    ii  erlang-jinterface             
    1:14.b.4-dfsg-1ubuntu1        Java communication tool to Erlang
    ii  erlang-manpages               
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP manual pages
    ii  erlang-megaco                 
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP implementation of Megaco/H.248 protocol
    ii  erlang-mnesia                 
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP distributed relational/object hybrid database
    ii  erlang-mode                   
    1:14.b.4-dfsg-1ubuntu1        Erlang major editing mode for Emacs
    ii  erlang-nox                    
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP applications that don't require X Window System
    ii  erlang-observer               
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application for investigating distributed systems
    ii  erlang-odbc                   
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP interface to SQL databases
    ii  erlang-os-mon                 
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP operating system monitor
    ii  erlang-parsetools             
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP parsing tools
    ii  erlang-percept                
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP concurrency profiling tool
    ii  erlang-pman                   
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP process manager
    ii  erlang-public-key             
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP public key infrastructure
    ii  erlang-reltool                
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP release management tool
    ii  erlang-runtime-tools          
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP runtime tracing/debugging tools
    ii  erlang-snmp                   
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP SNMP applications
    ii  erlang-src                    
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP applications sources
    ii  erlang-ssh                    
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP implementation of SSH protocol
    ii  erlang-ssl                    
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP implementation of SSL
    ii  erlang-syntax-tools           
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP modules for handling abstract Erlang syntax trees
    ii  erlang-test-server            
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP server for automated application testing
    ii  erlang-toolbar                
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP graphical toolbar
    ii  erlang-tools                  
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP various tools
    ii  erlang-tv                     
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP table viewer
    ii  erlang-typer                  
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP code type annotator
    ii  erlang-webtool                
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP helper for web-based tools
    ii  erlang-x11                    
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP applications that require X Window System
    ii  erlang-xmerl                  
    1:14.b.4-dfsg-1ubuntu1        Erlang/OTP XML tools

    erlang-dev包含頭文件,erlang-src包含源代碼,erlang-debugger包含調(diào)試工具,erlang-base包含虛擬機(jī)

    還可以根據(jù)package 名字的suffix察看erlang man doc,比如
    man 3erl erlang
    man 3erl mnesia
    man 3erl io

    posted @ 2013-01-15 11:34 Milo的海域 閱讀(676) | 評(píng)論 (0)編輯 收藏

    命令行調(diào)試erlang程序報(bào)錯(cuò):
    2> c(hello, [debug_info]).
    {ok
    ,hello}
    3> im().
    Call to i:im/
    0 in application debugger failed.
    ok

    google之原來(lái)是erlang-debugger沒裝
    sudo apt-get install erlang-debugger

    然后Monitor窗口就出來(lái)了。不過用eclipse 的erlide插件調(diào)試也可以。

    posted @ 2013-01-11 17:06 Milo的海域 閱讀(455) | 評(píng)論 (0)編輯 收藏

    mvn 執(zhí)行外部命令
    命令行模式
    mvn exec:exec -Dexec.executable=sh -Dexec.workingdir=./bin -Dexec.args=hello.sh

    配置文件形式
                            <plugin>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>exec-maven-plugin</artifactId>
                                    <executions>
                                            <execution>
                                                    <id>test-exec</id>
                                                    <phase>initialize</phase>
                                                    <configuration>
                                                            <executable>sh</executable>
                                                            <workingDirectory>./bin</workingDirectory>
                                                            <arguments>
                                                                    <argument>hello.sh</argument>
                                                            </arguments>
                                                    </configuration>
                                                    <goals>
                                                            <goal>exec</goal>
                                                    </goals>
                                            </execution>
                                    </executions>
                            </plugin>

    mvn 生成java項(xiàng)目
    生成骨架
    mvn archetype:generate -DgroupId=com.abc.product -DartifactId=product -DpackageName=com.abc.product -DarchetypeArtifactId=maven-archetype-quickstart

    轉(zhuǎn)成eclipse能識(shí)別的java 項(xiàng)目
    mvn eclipse:eclipse
    導(dǎo)入eclipse 然后coding

    mvn進(jìn)行單元測(cè)試
                            <plugin>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-surefire-plugin</artifactId>
                                    <version>
    2.12.4</version>
                                    <configuration>
                                            <forkMode>pertest</forkMode>
                                            <excludes>
                                                    <exclude>**/perftest/*.java</exclude>
                                            </excludes>
                                            <systemProperties>
                                                    <property>
                                                            <name>log4j.configuration</name>
                                                            <value>target/test-classes/log4j.properties</value>
                                                    </property>
                                            </systemProperties>
                                    </configuration>
                            </plugin>

    mvn進(jìn)行code coverage統(tǒng)計(jì)
      <reporting>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>emma-maven-plugin</artifactId>
            <version>1.0-alpha-3</version>
            <inherited>true</inherited>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>surefire-report-maven-plugin</artifactId>
            <inherited>true</inherited>
          </plugin>
        </plugins>
      </reporting>

    mvn生成javadoc
                            <plugin>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-javadoc-plugin</artifactId>
                                    <version>
    2.9</version>
                                    <configuration>
                                            <show>private</show>
                                    </configuration>
                                    <executions>
                                            <execution>
                                                    <id>attach-javadocs</id>
                                                    <goals>
                                                            <goal>javadoc</goal>
                                                            <goal>test-javadoc</goal>
                                                    </goals>
                                                    <phase>site</phase>
                                            </execution>
                                    </executions>
                            </plugin>

    posted @ 2013-01-10 13:33 Milo的海域 閱讀(1289) | 評(píng)論 (0)編輯 收藏

    最近項(xiàng)目要用JNI, 涉及到用java.library.path這個(gè)參數(shù),開始以為只要ldconfig能識(shí)別到的so文件java 一定能找到,可惜并不是這樣。。
    要想java程序找到共享庫(kù)還是要在執(zhí)行java程序的時(shí)候指定java.library.path,用eclipse的話可以設(shè)置如下:
    Properties->Run/Debug settings->Arguments->VM arguments
    -----------------------------------------
    -Djava.library.path=/home/miaoyachun/workspace/JNIC/Release
    這個(gè)是傳統(tǒng)的方式,google了下有個(gè)tricky的方式讓程序動(dòng)態(tài)修改java.library.path
        private static void loadJNILibDynamically() {
            
    try {
                System.setProperty(
    "java.library.path", System.getProperty("java.library.path")
                        
    + ":/home/miaoyachun/workspace/JNIC/Release/");
                Field fieldSysPath 
    = ClassLoader.class.getDeclaredField("sys_paths");
                fieldSysPath.setAccessible(
    true);
                fieldSysPath.set(
    nullnull);

                System.loadLibrary(
    "JNIC");
            } 
    catch (Exception e) {
                
    // do nothing for exception
            }
        }

    事實(shí)上linux下還有個(gè)環(huán)境變量LD_LIBRARY_PATH,如果lib能在這個(gè)path里找到,java.library.path就不用配置了,而且不需要關(guān)心lib之間依賴的問題。java.library.path在這方面就弱很多,比如lib依賴其他目錄的lib等。

    posted @ 2012-12-06 11:05 Milo的海域 閱讀(6865) | 評(píng)論 (0)編輯 收藏

    今天有同事反應(yīng)一個(gè)網(wǎng)絡(luò)現(xiàn)象,一個(gè)多網(wǎng)卡環(huán)境,發(fā)給eth1的數(shù)據(jù)包都被eth0接收了。
    第一印象是arp的問題。Google了下得到了確認(rèn),有個(gè)相關(guān)的kernal參數(shù):
    arp_ignore - INTEGER
    Define different modes for sending replies in response to
    received ARP requests that resolve local target IP addresses:
    0 - (default): reply for any local target IP address, configured
    on any interface
    1 - reply only if the target IP address is local address
    configured on the incoming interface
    2 - reply only if the target IP address is local address
    configured on the incoming interface and both with the
    sender's IP address are part from same subnet on this interface
    3 - do not reply for local addresses configured with scope host,
    only resolutions for global and link addresses are replied
    4-7 - reserved
    8 - do not reply for all local addresses
    默認(rèn)是0,解決這個(gè)問題需要配置為1

    臨時(shí)配置下
    sysctl -w net.ipv4.conf.all.arp_ignore=1

    持久配置
    sysctl -w net.ipv4.conf.all.arp_ignore=1
    echo 'net.ipv4.conf.all.arp_ignore
    =1' >> /etc/sysctl.conf

    這個(gè)弄好可以重啟network服務(wù)來(lái)確保其他機(jī)器更新arp cache,如果不方便重啟network,自己手動(dòng)敲arping命令,比如
    arping -q -A -c 1 -I eth1 10.197.24.177
    這個(gè)命令是在 /etc/sysconfig/network-scripts/ifup-eth里看到的

    如果機(jī)器比較少,也可以直接用arp -d 來(lái)刪除相關(guān)的cache,建議上面的那種發(fā)廣播的方式。

    posted @ 2012-11-27 17:16 Milo的海域 閱讀(663) | 評(píng)論 (0)編輯 收藏

    檢測(cè)磁盤相關(guān)信息   
        smartctl -a /dev/sda
    (smartctl工具來(lái)自smartmontools, 可以apt-get install smartmontools來(lái)安裝)

    檢測(cè)所有raid設(shè)備
        mdadm -Ds

    檢測(cè)具體raid設(shè)備信息
        mdadm -D /dev/md0

    創(chuàng)建raid設(shè)備
       mdadm --create --verbose /dev/md0 --level=raid0 --raid-devices=8 /dev/sdd /dev/sdc /dev/sdf /dev/sde /dev/sdg /dev/sdh /dev/sdi /dev/sdj

    停止raid設(shè)備
        mdadm -S /dev/md0

    格式化raid設(shè)備
        mkfs -t xfs -f /dev/md0

    掛載raid設(shè)備
       mount -t xfs /dev/md0 /raid

    切換raid模式的步驟
        1. umount if mounted : umount /raid
        2. stop raid device:  mdadm -S /dev/md0
        3. create raid: mdadm --create ...
        4. update /etc/mdadm.conf with output of 'mdadm -Ds', 用來(lái)開機(jī)自動(dòng)組raid
        5. update /etc/fstab, 如果需要開機(jī)自動(dòng)mount

    Ref:
    http://francs3.blog.163.com/blog/static/40576727201212145744783/
    http://hi.baidu.com/powersaven/item/1da2dc147a8be2e25f53b19e

    posted @ 2012-11-07 13:23 Milo的海域 閱讀(266) | 評(píng)論 (0)編輯 收藏

    關(guān)于alternatives的用法


    alternatives --install /usr/bin/java java /opt/jdk1
    .5.0_22/bin/java 15000
    alternatives --install /usr/bin/javac javac /opt/jdk1
    .5.0_22/bin/javac 15000
    alternatives --config java
    alternatives --config javac
    最近切換桌面環(huán)境到ubuntu, 發(fā)現(xiàn)alternatives這個(gè)工具改名了:update-alternatives
    用法還是一樣的。。

    posted @ 2012-10-26 13:31 Milo的海域 閱讀(814) | 評(píng)論 (0)編輯 收藏

    直接上C的實(shí)現(xiàn)
    typedef struct Foo {
        
    int len;
        
    char name[100];
    } Foo_t;

    JNIEXPORT jint JNICALL
    Java_TestJNI_foo(JNIEnv 
    *env, jobject obj, jobject fooObj) {

        Foo_t 
    * bar = malloc(sizeof(Foo_t));
        jclass clazz;
        jfieldID fid;

        
    //init the bar data of C
        strcpy(bar->name, "Yachun Miao");
        bar
    ->len = strlen(bar->name);

        
    // mapping bar of C to foo
        clazz = (*env)->GetObjectClass(env, fooObj);
        
    if (0 == clazz) {
            printf(
    "GetObjectClass returned 0\n");
            
    return (-1);
        }
        fid 
    = (*env)->GetFieldID(env, clazz, "len""I");
        (
    *env)->SetLongField(env, fooObj, fid, bar->len);

        fid 
    = (*env)->GetFieldID(env, clazz, "name""Ljava/lang/String;");
        jstring name 
    = (*env)->NewStringUTF(env, bar->name);
        (
    *env)->SetObjectField(env, fooObj, fid, name);

        free(bar);
        
    return 0;
    }

    對(duì)應(yīng)的Java調(diào)用
    public class Foo {
        
    protected int len;
        
    protected String name;
    }


        
    private static native int foo(Foo fooObj);

        
    public static void main(String args[]) {
            System.loadLibrary(
    "mylib");

            Foo foo 
    = new Foo();
            foo(foo);
            System.out.println(foo.name);
            System.out.println(foo.len);

        }

    參考鏈接
    http://www.steveolyo.com/JNI/JNI.html#CSTRCJ
    http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/types.html

    posted @ 2012-10-12 16:40 Milo的海域 閱讀(3864) | 評(píng)論 (0)編輯 收藏

    平時(shí)要用惡心的citrix Xenapp & citrix receiver 工作環(huán)境,裝完后發(fā)現(xiàn)client端不能復(fù)制內(nèi)容到server端,這樣會(huì)對(duì)工作造成很大的困擾。
    偶然發(fā)現(xiàn)citrix receiver的進(jìn)程上有個(gè)-file的選項(xiàng),會(huì)指定個(gè)臨時(shí)配置文件,里面提及
    ClipboardAllowed=off
    于是grep下這個(gè)關(guān)鍵字,發(fā)現(xiàn)~/ICAClient/linuxx86/config/All_Regions.ini 也有個(gè)類似的
    ClipboardAllowed=*
    改為
    ClipboardAllowed=true
    然后重新開Xenapp session之后發(fā)現(xiàn)已經(jīng)可以黏貼了。

    按照這個(gè)思路,使用windows的同事使用如下的方式打通兩端clipboard
    1. 打開系統(tǒng)注冊(cè)表編輯器
    2. 定位HKEY_CURRENT_USER\Software\Citrix\ICA Client\Engine\Lockdown Profiles\All Regions\Lockdown\Virtual Channels\Clipboard
    3. 修改ClipboardAllowed為1
    4. 注銷當(dāng)前用戶(或許需要)

    如果Xenapp server上使用vnc viewer之類的Xclient,如果想打通到vnc server的clipboard,還需要在vnc server所在linux主機(jī)開啟以下進(jìn)程
    vncconfig -nowin &
    這個(gè)有點(diǎn)不理解,但確實(shí)可行。待真相。。

    posted @ 2012-09-10 15:55 Milo的海域 閱讀(3491) | 評(píng)論 (1)編輯 收藏


    miaoyachun@ymiao:~$ /usr/lib/i386-linux-gnu/ibus/ibus-x11 --kill-daemon
    ^Z
    [1]+  Stopped                 /usr/lib/i386-linux-gnu/ibus/ibus-x11 --kill-daemon
    miaoyachun@ymiao:~$ bg
    [1]+ /usr/lib/i386-linux-gnu/ibus/ibus-x11 --kill-daemon &
    miaoyachun@ymiao:~$
    然后就可以了。。

    posted @ 2012-09-04 17:12 Milo的海域 閱讀(557) | 評(píng)論 (0)編輯 收藏

    今天發(fā)現(xiàn)ubunto12.4沒有默認(rèn)的瀏覽器,導(dǎo)致所有的鏈接打開的時(shí)候從用gedit。google上找到了解決方法:
    編輯以下內(nèi)容:
    [Desktop Entry]
    Version
    =14.0
    Name
    =Mozilla Firefox Web Browser
    Comment
    =Browse the World Wide Web
    GenericName
    =Web Browser
    Keywords
    =Internet;WWW;Browser;Web;Explorer
    Exec=/opt/firefox/firefox %u
    Terminal
    =false
    X-MultipleArgs
    =false
    Type
    =Application
    Icon
    =firefox
    Categories
    =GNOME;GTK;Network;WebBrowser;
    MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ftp;x-scheme-handler/chrome;video/webm;application/x-xpinstall;
    StartupNotify=true
    Actions
    =NewWindow;
    到文件~/.local/share/applications/firefox.desktop, 并保存退出。
    執(zhí)行:
    update-desktop-database ~/.local/share/applications/

    配好以后"System Settings -> Detail -> Default Applications -> Web" list里就會(huì)有firefox了。

    Ref: http://askubuntu.com/questions/166455/how-do-i-make-luakit-my-default-browser

    posted @ 2012-08-20 11:28 Milo的海域 閱讀(1026) | 評(píng)論 (0)編輯 收藏

    When play with eclim (eclipse style vim), i found its "LocateFile" command not work well when "invpaste" enabled in vim.
    Solution is disable it by
    " set invpaste

    posted @ 2012-08-06 14:56 Milo的海域 閱讀(264) | 評(píng)論 (0)編輯 收藏

    發(fā)現(xiàn)用curl從jetty服務(wù)器上download文件的速度比較慢大概只有4M/s, 開始以為curl有默認(rèn)的limit-rate,設(shè)置為1G以后發(fā)現(xiàn)還是慢。
    然后開始懷疑是jetty server的問題。看SslSelectChannelConnector的responseBufferSize比較像,反復(fù)實(shí)驗(yàn)發(fā)現(xiàn)原來(lái)是由于headerBufferSize太小。
    改為32K以后:
            SslSelectChannelConnector connector = new SslSelectChannelConnector();
            
            connector.setRequestBufferSize(
    32768);

    效果:
    curl -k https://USER:PASSWD@HOST:PORT/api/internal/file?filename=/path/to/file > /dest/to/file
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                                 Dload     Upload   Total   Spent     Left   Speed
    100  723M  100  723M    0     0   29.3M      0       0:00:24  0:00:24 --:--:-- 29.4M

    ref: http://wiki.eclipse.org/Jetty/Howto/Configure_Connectors

    posted @ 2012-07-18 18:22 Milo的海域 閱讀(612) | 評(píng)論 (0)編輯 收藏

    PHP curl option "CURLOPT_SSL_VERIFYPEER=false"  is same thing of '-k or --insecure' option of curl command.

    ref: http://curl.haxx.se/docs/sslcerts.html

    posted @ 2012-07-17 17:39 Milo的海域 閱讀(813) | 評(píng)論 (0)編輯 收藏

    主站蜘蛛池模板: 亚洲国产福利精品一区二区| www.免费在线观看| 国产偷v国产偷v亚洲高清| 一级做a爰黑人又硬又粗免费看51社区国产精品视 | 免费VA在线观看无码| 国产免费久久精品久久久| 麻豆亚洲AV成人无码久久精品 | 久久精品熟女亚洲av麻豆| 成人免费在线视频| 亚洲日韩精品无码AV海量| 日本视频免费在线| 国产午夜亚洲精品不卡电影| 免费人成视网站在线观看不卡| 欧洲亚洲综合一区二区三区| 亚洲国产一区视频| 亚洲人成77777在线播放网站不卡 亚洲人成77777在线观看网 | 日本精品人妻无码免费大全| 在线观看亚洲AV每日更新无码| 在线A级毛片无码免费真人 | 最近中文字幕免费mv在线视频 | 免费看黄网站在线看| 国产成人毛片亚洲精品| 波霸在线精品视频免费观看| 国产亚洲av片在线观看播放| 免费国产99久久久香蕉| 337p欧洲亚洲大胆艺术| 免费看黄视频网站| 日韩亚洲不卡在线视频中文字幕在线观看 | 二个人看的www免费视频| 亚洲av午夜成人片精品网站| 久久免费高清视频| 亚洲成人免费网站| 免费视频中文字幕| 亚欧洲精品在线视频免费观看| 亚洲国产精品无码久久SM| 永久在线观看www免费视频| 国产.亚洲.欧洲在线| 啊v在线免费观看| 久青草视频97国内免费影视| 色噜噜综合亚洲av中文无码| 久久久久国色AV免费观看性色|