Overturn of HFT Market – (High frequency trading)
High-frequency trading (HFT) is the use of sophisticated technological tools and computer algorithms to transact a large number of orders at very fast speeds. HFT uses complex algorithms to analyze multiple markets and execute orders in seconds or fractions of a second based on market conditions. High-frequency traders usually do not hold their portfolios overnight, they move in and out of short-term positions aiming to capture sometimes just a fraction of a cent in profit on every trade, they typically compete against other HFTs, rather than long-term investors. HFT is accounted for more than 50 percent of all U.S. equity volume.
The trading market is very dynamic and competitive, by 2007 Unix was the market standard, in 2008 started the adoption of Linux in trading market, due the Linux kernel’s ability to pass messages very quickly, then it became the standard between 2008 and 2012. In early of 2013 Oracle announced its new line of Sparc servers with T5 processor and it has been changing the market again.
In order to offer a competitive HFT solution to the market, it is important to care about the hardware where the solution will be running, the software should be developed to use the all advanced hardware and operational system benefits. Oracle’s processor offers resources like software on silicon, where some algorithms are put out of the software and placed into hardware besides the operational system Solaris that takes full advantage of the hardware features and can provide real time features to the trade’s process.
Another important point is about the data, the trade process should be able to handle data in real-time, therefore a solution to cache the data in memory is crucial to a HFT process.
Oracle Coherence is the industry leading in-memory data grid solution that enables organizations to predictably scale mission-critical applications by providing fast access to frequently used data.
The main reason of the market changing is the integration of hardware and software that only Oracle can offer.
Software on Silicon
Oracle announced in early 2013 its new Sparc T5 processor, it is twice as fast as their T4 predecessors and the world’s fastest microprocessor for database and java application.
Oracle’s new SPARC T5 servers have set 17 world records and are the world’s best platforms for enterprise computing at any scale, delivering the best value for database and enterprise applications.
Sparc T5 has 16 cores, each core can support up to eight independent threads or strands, a Sparc Server scales up to 8 sockets, so for the operating system there are a total of 1024 CPUs.
According to Oracle Sparc processor roadmap, each generation will have 2x performance than its prior generation, they will do that due Software on cilicon concept, where the algorithm is put out of software, and placed into hardware, they have done this for encryption/decryption on T4/T5 processors, and for the next generation they will do it for:
- Database Query
- Compression
- Encryption
- Cluster Interconnect
- Application Data Protection
The following graph represents the comparison of end-to-end overall application throughput performance including both SSL and WS-Security operations using hardware-assisted (Software on silicon) cryptographic acceleration and without using them. The tests ran a Java EE/JAX-WS Web Services application using a 500k XML message payload:
The results showed using Oracle SPARC hardware-assisted cryptographic acceleration significantly contributed to combined SSL/TLS and WS-Security scenarios delivering more than 200% of overall application performance gain for Two-way SSL and WS-Security operations in comparison with SSL/WS-Security operations using software.
Scripts to monitoring the Oracle ASM disks, files and volumes
This is a set of scripts to help on Oracle ASM Monitoring
Space used in ASM Disk Groups
SET LINESIZE 145 SET PAGESIZE 9999 SET VERIFY off COLUMN group_name FORMAT a20 HEAD 'Disk Group|Name' COLUMN sector_size FORMAT 99,999 HEAD 'Sector|Size' COLUMN block_size FORMAT 99,999 HEAD 'Block|Size' COLUMN allocation_unit_size FORMAT 999,999,999 HEAD 'Allocation|Unit Size' COLUMN state FORMAT a11 HEAD 'State' COLUMN type FORMAT a6 HEAD 'Type' COLUMN total_mb FORMAT 999,999,999 HEAD 'Total Size (MB)' COLUMN used_mb FORMAT 999,999,999 HEAD 'Used Size (MB)' COLUMN pct_used FORMAT 999.99 HEAD 'Pct. Used' break on report on disk_group_name skip 1 compute sum label "Grand Total: " of total_mb used_mb on report SELECT name group_name , sector_size sector_size , block_size block_size , allocation_unit_size allocation_unit_size , state state , type type , total_mb total_mb , (total_mb - free_mb) used_mb , ROUND((1- (free_mb / total_mb))*100, 2) pct_used FROM v$asm_diskgroup ORDER BY name /
Disks contained within Disk Groups
SET ECHO OFF SET FEEDBACK 6 SET HEADING ON SET LINESIZE 180 SET PAGESIZE 50000 SET TERMOUT ON SET TIMING OFF SET TRIMOUT ON SET TRIMSPOOL ON SET VERIFY OFF CLEAR COLUMNS CLEAR BREAKS CLEAR COMPUTES COLUMN disk_group_name FORMAT a25 HEAD 'Disk Group Name' COLUMN disk_file_path FORMAT a20 HEAD 'Path' COLUMN disk_file_name FORMAT a20 HEAD 'File Name' COLUMN disk_file_fail_group FORMAT a20 HEAD 'Fail Group' COLUMN total_mb FORMAT 999,999,999 HEAD 'File Size (MB)' COLUMN used_mb FORMAT 999,999,999 HEAD 'Used Size (MB)' COLUMN pct_used FORMAT 999.99 HEAD 'Pct. Used' BREAK ON report ON disk_group_name SKIP 1 COMPUTE sum LABEL "" OF total_mb used_mb ON disk_group_name COMPUTE sum LABEL "Grand Total: " OF total_mb used_mb ON report SELECT NVL(a.name, '[CANDIDATE]') disk_group_name , b.path disk_file_path , b.name disk_file_name , b.failgroup disk_file_fail_group , b.total_mb total_mb , (b.total_mb - b.free_mb) used_mb , ROUND((1- (b.free_mb / b.total_mb))*100, 2) pct_used FROM v$asm_diskgroup a RIGHT OUTER JOIN v$asm_disk b USING (group_number) ORDER BY a.name /
List of ASM files as well as its volume information
SET ECHO OFF SET FEEDBACK 6 SET HEADING ON SET LINESIZE 180 SET PAGESIZE 50000 SET TERMOUT ON SET TIMING OFF SET TRIMOUT ON SET TRIMSPOOL ON SET VERIFY OFF CLEAR COLUMNS CLEAR BREAKS CLEAR COMPUTES COLUMN full_path FORMAT a75 HEAD 'ASM File Name / Volume Name / Device Name' COLUMN system_created FORMAT a8 HEAD 'System|Created?' COLUMN bytes FORMAT 9,999,999,999,999 HEAD 'Bytes' COLUMN space FORMAT 9,999,999,999,999 HEAD 'Space' COLUMN type FORMAT a18 HEAD 'File Type' COLUMN redundancy FORMAT a12 HEAD 'Redundancy' COLUMN striped FORMAT a8 HEAD 'Striped' COLUMN creation_date FORMAT a20 HEAD 'Creation Date' COLUMN disk_group_name noprint BREAK ON report ON disk_group_name SKIP 1 COMPUTE sum LABEL "" OF bytes space ON disk_group_name COMPUTE sum LABEL "Grand Total: " OF bytes space ON report SELECT CONCAT('+' || db_files.disk_group_name, SYS_CONNECT_BY_PATH(db_files.alias_name, '/')) full_path , db_files.bytes , db_files.space , NVL(LPAD(db_files.type, 18), '<DIRECTORY>') type , db_files.creation_date , db_files.disk_group_name , LPAD(db_files.system_created, 4) system_created FROM ( SELECT g.name disk_group_name , a.parent_index pindex , a.name alias_name , a.reference_index rindex , a.system_created system_created , f.bytes bytes , f.space space , f.type type , TO_CHAR(f.creation_date, 'DD-MON-YYYY HH24:MI:SS') creation_date FROM v$asm_file f RIGHT OUTER JOIN v$asm_alias a USING (group_number, file_number) JOIN v$asm_diskgroup g USING (group_number) ) db_files WHERE db_files.type IS NOT NULL START WITH (MOD(db_files.pindex, POWER(2, 24))) = 0 CONNECT BY PRIOR db_files.rindex = db_files.pindex UNION SELECT '+' || volume_files.disk_group_name || ' [' || volume_files.volume_name || '] ' || volume_files.volume_device full_path , volume_files.bytes , volume_files.space , NVL(LPAD(volume_files.type, 18), '<DIRECTORY>') type , volume_files.creation_date , volume_files.disk_group_name , null FROM ( SELECT g.name disk_group_name , v.volume_name volume_name , v.volume_device volume_device , f.bytes bytes , f.space space , f.type type , TO_CHAR(f.creation_date, 'DD-MON-YYYY HH24:MI:SS') creation_date FROM v$asm_file f RIGHT OUTER JOIN v$asm_volume v USING (group_number, file_number) JOIN v$asm_diskgroup g USING (group_number) ) volume_files WHERE volume_files.type IS NOT NULL /
Disks performance metric
SET ECHO OFF SET FEEDBACK 6 SET HEADING ON SET LINESIZE 256 SET PAGESIZE 50000 SET TERMOUT ON SET TIMING OFF SET TRIMOUT ON SET TRIMSPOOL ON SET VERIFY OFF CLEAR COLUMNS CLEAR BREAKS CLEAR COMPUTES COLUMN disk_group_name FORMAT a20 HEAD 'Disk Group Name' COLUMN disk_path FORMAT a20 HEAD 'Disk Path' COLUMN reads FORMAT 999,999,999,999 HEAD 'Reads' COLUMN writes FORMAT 999,999,999,999 HEAD 'Writes' COLUMN read_errs FORMAT 999,999,999 HEAD 'Read|Errors' COLUMN write_errs FORMAT 999,999,999 HEAD 'Write|Errors' COLUMN read_time FORMAT 999,999,999,999 HEAD 'Read|Time' COLUMN write_time FORMAT 999,999,999,999 HEAD 'Write|Time' COLUMN bytes_read FORMAT 999,999,999,999,999 HEAD 'Bytes|Read' COLUMN bytes_written FORMAT 999,999,999,999,999 HEAD 'Bytes|Written' BREAK ON report ON disk_group_name SKIP 2 COMPUTE sum LABEL "" OF reads writes read_errs write_errs read_time write_time bytes_read bytes_written ON disk_group_name COMPUTE sum LABEL "Grand Total: " OF reads writes read_errs write_errs read_time write_time bytes_read bytes_written ON report SELECT a.name disk_group_name , b.path disk_path , b.reads reads , b.writes writes , b.read_errs read_errs , b.write_errs write_errs , b.read_time read_time , b.write_time write_time , b.bytes_read bytes_read , b.bytes_written bytes_written FROM v$asm_diskgroup a JOIN v$asm_disk b USING (group_number) ORDER BY a.name /
ASMLib for RHEL6
Are you worried because you can’t find asmlib for RHEL 6?
don’t worry, this article clarifies that.
ASMLib
ASMLib is an optional set of tools and a kernel driver that can be inserted between ASM and the hardware, as well as an application library used by the Oracle database software to access ASM disks. It is a support library for the ASM feature of Oracle 10g and 11g single instance database servers as well as RAC installations. ASM and regular database instances can use ASMLib as an alternative interface for disk access. ASMLib has three components:
- Kernel driver – oracleasm is a Linux kernel driver also known as the Oracle ASMLib kernel driver.
This is an open-source (GPL) kernel driver and is available from Oracle as source and binary
RPMs. Note that although this driver is provided under an open source license, it has not been
accepted into the mainline Linux kernel.
- Support tools – oracleasm-support provides the utilities to manage the ASM library driver. Oracleasm-support is an open-source package (GPL) and is available from Oracle as source and binary RPMs.
- Application library – oracleasmlib package provides the actual ASM library. This is a closed source, binary-only RPM, available as a free download from Oracle.
Oracle introduced ASMLib in 2004 to provide Oracle workloads on Linux with performance and stability
comparable to equivalent workloads on UNIX. ASMLib addressed deficiencies – including a lack of async
and direct I/O — that existed in the 2.4 Linux kernel.
Kernel 2.6
The Linux community addressed these deficiencies in the 2.6 Linux kernel with the addition of udev and device-mapper multipath which together with LVM provided native multipathing, scalable native volume management, and persistent device naming. Additionally, the 2.6 Linux kernel added tools for handling large numbers of disks, especially SAN-attached disks.
Since the RHEL6’s kernel version is 2.6, the use of asmlib is no longer needed, in RHEL 6 is used UDEV and DirectIO instead.
UDEV
UDEV allows for rules that specify what device name is given to a specific device, regardless of which port is plugged into.
Direct I/O
When a process wants to access data from a file, the SO brings the data into a buffer cache in order to avoid frequency of disk accesses. Oracle database also keep the data in a area called Buffer Cache in SGA, this “doublecopying” of data results in more CPU consumption and adds overhead to the memory too, the use of Direct I/O is indicated in situations like that, applications like a database that wishes to bypass the SO buffering within the file system cache.
To enable the use of DirectI/O on Oracle the parameter disk_asynch_io must be set to true, which is set to true by default in Oracle 11g:
SQL> show parameter disk_asynch_io; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ disk_asynch_io boolean TRUE SQL>
Conclusion
The conclusion is that if you are using kernel 2.6 or higher the ASMLib is useless, there are native implementations(UDEV and DirectI/O) that replaced its needed, UDEV to persists the name of devices and the DirectIO to bypass the SO buffering.
Tuning linux server for Oracle database
Dozens of DBA and SysAdmin do not know how to calculate the kernel’s parameters correctly and most of times they use the default value as indicated in Oracle Documentation, I would say that most of the DBA do not even know the meaning of those parameters.
In this article I will describe the meaning of each OS paramater and how to calculate/sizing them.
Shared Memory
Shared memory allows processes to access common structures and data by placing them in shared memory segment. It is the fastest form of interprocess Communication (IPC) available since no kernel involvement occurs when data is passed between the processes. In fact, data does not need to be copied between the processes.
Oracle uses shared memory segments for Shared Global Area (SGA) which is an area of memory that is shared by Oracle processes. The size of the SGA has a significant impact to Oracle’s performance since it holds database buffer cache and much more.
Basically we use three parameters to scale shared memory:
SHMMAX
This parameter defines the maximum size in bytes of a single shared memory segment that a linux process can allocate.
SHMMNI
This parameter sets the system wide maximum number of shared memory segments. Oracle recommends SHMMNI to be at least 4096.
SHMALL
This parameter sets the total amount of shared memory pages that can be used system wide.
Memory Sizing
The steps bellow help to scale the parameters SHMMAX and SHMALL:
Obtain the total memory from the system
mem=$(free|grep Mem|awk '{print$2}')
Convert the value of $mem to bytes
totmem=$(echo "$mem*1024"|bc)
Get the Hugepagesize from /proc/meminfo
huge=$(grep Hugepagesize /proc/meminfo|awk '{print $2}')
Calculate what 75% of the total memory on the system for SHMMAX
max=$(echo "$totmem*75/100"|bc)
Divide the SHMMAX value by the Hugepagesize to get SHMALL
all=$(echo "$max/$huge"|bc)
Set the SHMMAX value in the /etc/sysctl.conf file
echo "kernel.shmmax = $max" >> /etc/sysctl.conf
Set the SHMALL value in the /etc/sysctl.conf file
echo "kernel.shmall = $all" >> /etc/sysctl.conf
Setting the maximum number of shared memory segments with SHMMNI.
echo "kernel.shmmni=4096" >> /etc/sysctl.conf
Memory Tuning
The linux kernel tunable parameter vm.swappiness (/proc/sys/vm/swappiness) can be used to define how aggressively memory pages are swapped to disk.
Linux moves memory pages that have not been accessed for some time to the swap space even if there is enough free memory available. By changing the percentage in /proc/sys/vm/swappiness you can control the swapping behavior, depending on the system configuration.
A high swappiness value means that the kernel will be more apt to unmap mapped pages. A low swappiness value means the opposite, the kernel will be less apt to unmap mapped pages. In other words, the higher the vm.swappiness value, the more the system will swap.
Swapping for Oracle is too bad
vm.swappiness=0
Maximum percentage of active memory that can have dirty pages
vm.dirty_background_ratio=3
Maximum percentage of total memory that can have dirty pages
vm.dirty_ratio=15
How long data can be in page cache before being expired (hundreths of a second)
vm.dirty_expire_centisecs=500
How often pdflush is activated to clean dirty pages (hundreths of asecond)
vm.dirty_writeback_centisecs=100
Setting Hugepages
Without HugePages, the memory of the SGA is divided into 4K pages, which have to be managed by the Linux kernel. Using HugePages, the page size can be increased to anything between 2MB and 256MB, thereby reducing the total number of pages to be managed by the kernel and therefore reducing the amount of memory required to hold the page table in memory. In addition to these changes, the memory associated with HugePages can not be swapped out, which forces the SGA to stay memory resident.
Setup the oracle user to be able to use hugepages in /etc/sysctl.conf
vm.hugetlb_shm_group=`id -g oracle`
Calculating the recommended number of HugePages, use the following formula:
(SGA+PGA+(20KB * # of Oracle processes running)) / 2MB
For example:
(20GB SGA + 10GB PGA + (20KB * 1,000 Oracle processes)) / 2MB = 15369
Include the parameter vm.nr_hugepages in /etc/sysctl.conf
vm.nr_hugepages=15369
Setting Semaphores
Semaphores are counters which are used to provide synchronization between processes for shared resources like shared memory. Oracle’s process concur in order to access the SGA, which is allocated in a shared memory area, thereby the number of semaphores must be higher than the number of oracle’s process parameter.
The number of semaphores per set can be defined through the kernel parameter SEMMSL. In /etc/sysctl.conf the entry for semphores is:
kernel.sem="250 32000 100 142"
The first value, SEMMSL, is the maximum number of semaphores per semaphore set
The second value, SEMMNS, defines the total number of semaphores for the system
The third value, SEMOPM, defines the maximum number of semaphore operations per semaphore call
The last value, SEMMNI, defines the number of entire semaphore sets for the system
Network tuning
Receive socket buffer size
net.core.rmem_default=262144 net.core.rmem_max=4194304
Send socket buffer size
net.core.wmem_default=262144 net.core.wmem_max=4194304
TCP socket buffer size
net.ipv4.tcp_rmem=4096 262144 4194304 net.ipv4.tcp_wmem=4096 262144 4194304
How often to send keep alive packets when a connection is unused
net.ipv4.tcp_keepalive_time=30
How long the kernel waits in between probes
net.ipv4.tcp_keepalive_intvl=60
How many probes are sent before a connection is considered broken
net.ipv4.tcp_keepalive_probes=9
How many times to retry before killing the connection
net.ipv4.tcp_retries2=3
How many times to retry transmitting the syn packet
net.ipv4.tcp_syn_retries=2
Configuring Database Failover on JBoss
JBoss supports database failover for datasources, this functionality is supported for both local datasources and XA datasources.
If the primary database becomes unavailable, it will try every database listed, until it finds one that sticks. If for a connection request it has tried all the URLs in the list, and none worked, an exception will be thrown with a message saying that none of the URLs worked. The current selection policy is round-robin and so will not revert to the primary database when it becomes available unless bounce the instance.
Basically what you must to do is configure some elements in datasource file, the following elements must be used to configure your failover datasource:
-
<ha-local-tx-datasource> - The root element for local datasources that support failover.
-
<url-delimeter>which contains a string that is used as a delimeter between URLs in connection-url.
-
<connection-url> - List of connection urls
Configure local datasource for failover:
<ha-local-tx-datasource> <jndi-name>HADefaultDS</jndi-name> <connection-url>jdbc:oracle:thin:@server1:1521:jboss|jdbc:oracle:thin:@server2:1521:jboss|...</connection-url> <url-delimeter>|</url-delimeter> <driver-class>oracle.jdbc.OracleDriver</driver-class> <user-name>sa</user-name> <password></password> </ha-local-tx-datasource>
Configure XA datasource for failover:
<ha-xa-datasource> <jndi-name>MockedHaXaDS</jndi-name> <track-connection-by-tx></track-connection-by-tx> <isSameRM-override-value>false</isSameRM-override-value> <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class> <xa-datasource-property name="URL">jdbc:oracle:thin:@server1:1521:jboss|jdbc:oracle:thin:@server2:1521:jboss|...</xa-datasource-property> <url-property>URL</url-property> <url-delimeter>|</url-delimeter> </ha-xa-datasource>
How to pack Oracle database’s binaries in a RPM file
This article describes how to create a RPM file with oracle’s binaries in it, in order to make easier the process of database installation.
Prerequisites
Install the packages rpmdevtools and rpm-build, these packages contains command line like rpmdev-setuptree and rpmbuild that will help to create the RPM structure
#yum install rpmdevtools rpm-build
The oracle database software must be installed on the machine
Generate the RPM structure
Inside the oracle’s home directory execute the command:
#rpmdev-setuptree
This command will create the following directory structure:
|-- rpmbuild |-- BUILD |-- RPMS |-- SOURCES |-- SPECS `-- SRPMS
RPM Contents SOURCES
The directory SOURCES must have a tar file with all files desired to be added in the RPM file
#tar -cvf oracle11.tar /home/oracle/.bash_profile /u01/app/oracle/product/11.2.0/rhdb/*
Configuration SPEC file
The directory SPEC is where the spec file with the instructions to create our RPM must be placed
One of the key parameter in this file is the “requires”, where a list of packages dependencies is configured.
Create a file called oracle11G.spec with the content bellow:
Name: oracle Version: 11 Release: 2%{?dist} Summary: Oracle 11G R2 Group: redhat License: GNU URL: http://www.redhat.com Source0: oracle11.tar #BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) Requires: binutils >= 2, glibc >= 2, nss-softokn-freebl >= 3, compat-libstdc++ >= 33, glibc-common >= 2, glibc-devel >= 2, glibc-headers >= 2, elfutils-libelf, elfutils-libelf-devel, gcc >= 4, gcc-c++ >= 4, ksh, libaio, libaio-devel, libgcc >= 4, libstdc++ >= 4, libstdc++-devel >= 4, make >= 3.81, numactl-devel >= 2, ld-linux.so.2()(32bit), sysstat >= 9 libfreebl3.so()(32bit), libc.so()(32bit), libaio.so.1()(32bit), libaio.so()(32bit), libgcc_s.so.1()(32bit), libstdc++.so.6()(32bit), libstdc++.so.5()(32bit) %description Oracle 11G R2 %build mkdir -p $RPM_BUILD_ROOT/home/oracle cp /home/oracle/.bash_profile $RPM_BUILD_ROOT/home/oracle mkdir -p $RPM_BUILD_ROOT/u01/app/oracle/product/11.2.0/rhdb/ cp -ra /u01/app/oracle/product/11.2.0/rhdb/* $RPM_BUILD_ROOT/u01/app/oracle/product/11.2.0/rhdb/ %pre groupadd oinstall groupadd dba useradd -g oinstall -G dba oracle echo redhat|passwd --stdin oracle %files /u01/* /home/* %post chown -R oracle:oinstall /u01 chmod -R 775 /u01 %changelog * Fri Sep 23 2011 Leandro Abite 1.0 - First version
Generating RPM file
The generation of the RPM file is made by the command rpmbuild passing the spec file as parameter
#rpmbuild -ba oracle11G.spec
if every thing is ok the rpm file should be created in the directory SRPMS
Requires
How to make the Apache redirect from http to https and vice versa automatically
There are some ways to do that, in this examples let’s use the module mod_rewrite.
Make sure that the module mod_rewrite is being loaded by your apache
We need tell apache the condiction to execute the redirect, edit the file $APACHE_HOME/conf/httpd.conf and add the following lines:
#Turn on the rewrite
RewriteEngine on
#Condiction and rule for redirect
RewriteCond %{REQUEST_URI} ^/(<YOUR URL>)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
Sample:
Let’s suppose you need to redirect the URL http://youserver/login.php to https://youserver/login.php, our configuration would be the follwing:
RewriteCond %{REQUEST_URI} ^/(login\.php)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
If there are a need to set up more than one URL, just copy and paste the 2 lines above and replace the name of the page.
Once the user request the url http://youserver/login.php he will remain in https even in pages that are not configured in httpd.conf, That happened because that configuration tell apache to get in https when the page login.php is requested, so we need tell Apache to get in http when some other page is requested, this is configured in the file $APACHE_HOME/conf.d/ssl.conf, do the same configuration done in file http.conf
Sample:
Let’s suppose that after the user pass througt the login he will get the home.php page, so add the following lines in the file $APACHE_HOME/conf.d/ssl.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(home\.php)
RewriteRule ^/(.*) http://%{SERVER_NAME}/$1 [R,L]
Don’t forget to restart the apache service
It’s done, 🙂 !!!
Converting Entity Objects to SelectItem Objects using reflection
This method is very useful for development JSP using JSF. This method converts a list of Entity Objects or any class that contains the items for a JSF ListBox to SelectItem Object. The class must have at least two methods:
- The id method that return de id of the Item
- The description method that return the description of the Item
public List<SelectItem> entityToSelectItem(List _items, String _idMethod, String _descMethod)throws Exception { List<SelectItem> items = new ArrayList<SelectItem>(); Method idMethod = null; Method descMethod = null; for (int i = 0; i < _items.size(); i++) { Object item = _items.get(i); // On the first run, initialize reflection methods for object if (idMethod == null) { Class obj = item.getClass(); idMethod = obj.getMethod(_idMethod, new Class[]{}); descMethod = obj.getMethod(_descMethod, new Class[]{}); } // invoke Methods String id = (String) idMethod.invoke(item, new Object[]{}); String name = (String) descMethod.invoke(item, new Object[]{}); SelectItem selectItem = new SelectItem(); selectItem.setLabel(name); selectItem.setValue(id.toString()); items.add(selectItem); } return items; }