2014/08/26

Installing Tomcat 7 + Postgres 9.3 on Amazon Linux


-------------------------------------------------------------------------------------------------------
Tomcat Part
-------------------------------------------------------------------------------------------------------

#install tomcat7

sudo yum install tomcat7-webapps tomcat7-docs-webapp tomcat7-admin-webapps
       
 

#auto startup


sudo chkconfig tomcat7 on
       
 

#redirect port


sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

sudo /sbin/service iptables save
       
 

-------------------------------------------------------------------------------------------------------
Postgres Part
-------------------------------------------------------------------------------------------------------

Install from rpm/yum from postgres repo

In the files
/etc/yum.repos.d/amzn-main.repo
and
/etc/yum.repos.d/amzn-updates.repo add the following in the
block [amzn-main]:

///////////////////////////////////////
exclude=postgresql*
///////////////////////////////////////

Then, install the repo rpm and run yum
# Change to home directory to download the software


cd ~/
       
 
# Get the right postgresql package (Redhat 64 Bit)


wget http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
       
 
# Install the package


sudo rpm -ivh pgdg-redhat93-9.3-1.noarch.rpm
sudo yum install postgresql93 postgresql93-server postgresql93-devel
       
 
# Check that the service is installed


sudo service postgresql-9.3 status
       
 
# should return "is stopped"

# init the DB


sudo service postgresql-9.3 initdb
       
 
# Start the DB

sudo service postgresql-9.3 start
       
 
# connect


sudo su - postgres
psql
       
 
# auto startup


sudo chkconfig postgresql-9.3 on
       
 
source

2014/07/11

Automatically Retry Failed Jobs in Quartz


Source: Automatically Retry Failed Jobs in Quartz

Retrying continuously until success:
If you want to keep trying over and over again until the job succeeds, all you have to do is throw a JobExecutionException with a flag to tell the scheduler to fire it again when it fails. The following code shows how:


class MyJob implements Job {
 
  public MyJob() {
  }
 
  public void execute(JobExecutionContext context)
                  throws JobExecutionException {
    try{
        //do something
    }
    catch(Exception e){
 
        Thread.sleep(10000); //sleep for 10 secs
 
        JobExecutionException e2 = new JobExecutionException(e);
        //fire it again
        e2.refireImmediately();
        throw e2;
    }
  }
}
       
 

Retrying n times:
It gets a bit more complicated if you want to retry a certain number of times only. You have to use a StatefulJob and hold a retryCounter in its JobDataMap, which you increment if the job fails. If the counter exceeds the maximum number of retries, then you can disable the job if you wish.




class MyJob implements StatefulJob {
 
  public MyJob() {
  }
 
  public void execute(JobExecutionContext context)
                                 throws JobExecutionException {
    JobDataMap dataMap = context.getJobDetail().getJobDataMap();
    int count = dataMap.getIntValue("count");
 
    // allow 5 retries
    if(count >= 5){
        JobExecutionException e = new JobExecutionException("Retries exceeded");
        //unschedule it so that it doesn't run again
        e.setUnscheduleAllTriggers(true);
        throw e;
    }
 
    try{
        //do something
 
        //reset counter back to 0
        dataMap.putAsString("count", 0);
    }
    catch(Exception e){
        count++;
        dataMap.putAsString("count", count);
        JobExecutionException e2 = new JobExecutionException(e);
 
        Thread.sleep(10000); //sleep for 10 secs
 
        //fire it again
        e2.refireImmediately();
        throw e2;
    }
  }
}
       
 

2014/05/03

Admob廣告收入


Admob廣告收入構成
收入=廣告展示量/1,000 * 千次展示收入
千次展示收入=點擊率 * 廣告單價
廣告單價,台灣大概0.1 USD,各國不一定
假設一個月
廣告展示量=100,000 次
點擊率 = (0.1%) 0.001
廣告收入=100000/1000*0.001*0.1=0.01USD
但是其他報告是說,
行動裝置平均每次點擊約有0.01 USD,一般網頁平均每次點擊約有0.1 USD
這報告告訴大家,錢真的不好賺啊 QQ

NGINX SSL/設定檔案

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #...