一 安装环境
系统版本ubuntu-10.10 (建议不要用10.10以上的版本,我用12.10出现了大量的问题)
安装镜像是 ubuntu-10.10-beta-desktop-i386.iso
硬件 HP-Z800 以及VM虚拟机环境都测试成功
需要连网环境以及软件源。(湖南大学校园网锐捷登陆方法见附录A)
ubuntu-10.10 软件源的设置:
http://blog.csdn.net/a8887396/article/details/8753535
二 gcc安装
由于sesc当初是使用gcc3.4.x编译,所以使用相同的编译器不容易出问题。
安装文件见gcc3.4.6目录
cpp-3.4_3.4.6-6ubuntu5_i386.deb gcc-3.4-base_3.4.6-6ubuntu5_i386.deb
gcc-3.4_3.4.6-6ubuntu5_i386.deb
cd gcc3.4.6
sudo chmod 777 *
sudo dpkg -i *
sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc
gcc -v 显示版本 gcc version 3.4.6 (Ubuntu 3.4.6-6ubuntu5)
三 安装sescutils
sescutils 是编译sesc能运行的程序的编译器。
1 修改sh软链接为bash
sudo ln -sf /bin/bash /bin/sh
ls -l /bin/sh 显示 /bin/sh -> /bin/bash 表示修改成功
2 安装前置软件(若你是和我一样是在新的系统中安装,这些你可能都要安装)
bison2.0和 flex (新版本的bison不行,若已有,删除,安装bison2.0)
bison的前置软件需要m4
sudo apt-get install m4
bison2.0的下载地址 http://ftp.gnu.org/gnu/bison/ 也可以用我下载好的
安装bison2.0
sudo tar zxvf bison-2.0.tar.gz
cd bison-2.0
sudo ./configure
sudo make
sudo make install
sudo apt-get install flex
安装 libncurses5-dev
若不安装,编译build-5-gdb时会提示 configure: error: no termcap library found
sudo apt-get install libncurses5-dev
3 要修改的地方
将 sescutils.tar.bz2 拷贝到$HOME目录下 (也就是 cd ~ 进入的目录)
tar -jxvf sescutils.tar.bz2
cd sescutils
cd build-mipseb-linux/
vim build-common
修改build-common中的三个参数为
GNUsrc=/blog_article/$HOME/sescutils/src_/p/index.html>
PREFIX=$HOME/sescutils/install
BUILD="i686-pc-linux-gnu"
4 编译步骤
sudo ./build-1-binutils
sudo ./build-2-gcc-core
sudo ./build-3-glibc
sudo ./build-4-gcc
sudo ./build-5-gdb
5 安装完成
四 安装SESC
1 下载方式
使用我修改过的包也可以,反正sesc已经从09年开始就没更新过了。
下面是在线下载的方法
安装 CVS
sudo apt-get install cvs
下载CVS
$cvs -d:pserver:anonymous@sesc.cvs.sourceforge.net:/cvsroot/sesc login
Note:需要输入密码 直接按回车
$cvs -z3 -d:pserver:anonymous@sesc.cvs.sourceforge.net:/cvsroot/sesc co -P sesc
2 安装需要的相关程序
sudo apt-get install binutils
sudo apt-get install zlib1g-dev
sudo apt-get install g++
这里我自动安装的是g++-4.3版本的 不知为何我找不到下面两个安装文件了
g++-3.4_3.4.6-1ubuntu2_i386
libstdc++6-dev_3.4.6-1ubuntu2_i386
据说是在 http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-3.4/ 下载的
但是我用g++-4.3来编译sesc 没有报奇怪的问题 发现问题再换吧。
3 解压sesc
在home目录下解压sesc.tar.gz
sudo tar zxvf sesc.tar.gz
生成一个sesc文件夹 其源码需要做些修改 如下: (我给的文件已经该过里)
sesc/src/libcore/FetchEngine.cpp 中 加上 #include <limits.h>
sesc/src/libmint/subst.cpp 中 include <linux/dirent.h>, 改为include<dirent.h>
在home下创建一个空文件夹 sesc-build 用来存放编译结果。
sudo mkdir sesc-build
cd sesc-build
../sesc/configure
sudo make
在报如下类似错误的文件中加上 #include <stdint.h>
ERROR‘uint32_t’ was not declared in this scope
在报如下类似错误的文件中加上 #include <limits.h>
ERROR: USHRT_CHAR undefined
测试是否安装成功
make testsim
五 第一个程序
1 修改路径参数
创建文件
vim setupsesc
写入如下内容
set +h
export PATH=$HOME/sescutils/install/bin:$HOME/sesc-build:$PATH
ech
It does not contain as many information as the Abstract Syntax Tree (AST) but is fast to create. For example the Outline view is using the Java model for its representation; this way the information in the Outline view can quickly get updated.
The Java model is defined in the org.eclipse.jdt.core plug-in. JDT Core (org.eclipse.jdt.core) is the plug-in that defines the core Java elements and API. You should always list this plug-in as a prerequisite when you are developing Java specific features.
JDT Core packages give you access to the Java model objects and headless Java IDE infrastructure. The JDT Core packages include:
org.eclipse.jdt.core - defines the classes that describe the Java model.
org.eclipse.jdt.core.compiler - defines an API for the compiler infrastructure.
org.eclipse.jdt.core.dom - supports Abstract Syntax Trees (AST) that can be used for examining the structure of a compilation unit down to the statement level.
org.eclipse.jdt.core.dom.rewrite - supports rewriting of Abstract Syntax Trees (AST) that can be used for manipulating the structure of a compilation unit down to the statement level.
org.eclipse.jdt.core.eval - supports the evaluation of code snippets in a scrapbook or inside the debugger.
org.eclipse.jdt.core.formatter - supports the formatting of compilation units, types, statements, expressions, etc.
org.eclipse.jdt.core.jdom - supports a Java Document Object Model (DOM) that can be used for walking the structure of a Java compilation unit.
org.eclipse.jdt.core.search - supports searching the workspace's Java model for Java elements that match a particular description.
org.eclipse.jdt.core.util - provides utility classes for manipulating .class files and Java model elements.
Project Element
Java Model element
Description
Java project
IJavaProject
The Java project which contains all other objects.
src folder / bin folder / or external library
IPackageFragmentRoot
Hold source or binary files, can be a folder or a library (zip / jar file)
Each package
IPackageFragment
Each package is below the IPackageFragmentRoot, sub-packages are not leaves of the package, they are listed directed under IPackageFragmentRoot
Java Source File
ICompilationUnit
The Source file is always below the package node
Types / Fields / Methods
IType / IField / IMethod
Types, fields and methods
之前提到的五大增强是被织入目标类的所有方法中。
但如果想选择性增强(织入某些类的某些方法上),则要借助于切点。
spring 主要通过org.springframework.aop.Pointcut 来描述切点
Pointcut接口定义
public interface Pointcut { /** * Return the ClassFilter for this pointcut. * @return the ClassFilter (never <code>null</code>) */ ClassFilter getClassFilter(); /** * Return the MethodMatcher for this pointcut. * @return the MethodMatcher (never <code>null</code>) */ MethodMatcher getMethodMatcher(); /** * Canonical Pointcut instance that always matches. */ Pointcut TRUE = TruePointcut.INSTANCE; }PointCut主要依赖于ClassFilter和MethodMatcher,通过ClassFilter可以定位到某些特定类中,通过MethodMatcher可以定位到某些具体方法。
切面:由切点和增强代码两部分组成。
spring用org.springframework.aop.Advisor表示切面。切面分三类:一般切面、切点切面、引介切面。
1. Advisor:表示一般的切面,仅依赖一个增强接口Advice,作用于目标类的所有方法,使用较少
2. PointcutAdvisor:表示具有切点的切面。包含了增强部分(Advice)和切点(Pointcut),可以灵活的针对某些特定的类、方法增强。
3. IntroductionAdvisor:对应引介增强的特殊的切面。
其中第2点的PointcutAdvisor使用场景最多,我们看下它的子类结构
a)DefaultPointcutAdvisor,通过任意Pointcut和Advice定义一个切面,不支持引介的切面类型,可以通过扩展子类实现自定义的切面
b)NameMatchMethodPointcutAdvisor,按方法名定义切点的切面
c)RegexpMethodPointcutAdvisor,按正则表达式匹配方法名进行切点定义的切面
d)AspectJExpressionPointcutAdvisor,用AspectJ切点表达式定义切点的切面
e)AspectJPointcutAdvisor,用AspectJ语法定义切点的切面
f)StaticMethodMatcherPointcutAdvisor,静态方法匹配器切点定义的切面,默认匹配所有的目标类
例子:
Seller.java
package tome.sample.Advisor; /** * 类Seller.java的实现描述:TODO 类实现描述 * * @author onlyone 2013-4-13 下午08:41:36 */ public class Seller { public void greetTo(String name) { System.out.println("seller greet to " + name + "!"); } }
Waiter.java
package tome.sample.Advisor; /** * 类Waiter.java的实现描述:TODO 类实现描述 * * @author onlyone 2013-4-13 下午08:41:44 */ public class Waiter { public void greetTo(String name) { System.out.println("waiter greet to " + name + "!"); } public void serveTo(String name) { System.out.println("waiter serving " + name + "!"); } }
package tome.sample.Advisor; import java.lang.reflect.Method; import org.springframework.aop.ClassFilter; import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; /** * 自定义切面 * * @author onlyone 2013-4-13 下午08:42:10 */ public class GreetingAdvisor extends StaticMethodMatcherPointcutAdvisor { /** * 匹配greetTo方法 */ public boolean matches(Method method, Class clazz) { return "greetTo".equals(method.getName()); } /** * 匹配Waiter及其子类 */ public ClassFilter getClassFilter() { return new ClassFilter() { public boolean matches(Class clazz) { return Waiter.class.isAssignableFrom(clazz); } }; } }
前置增强GreetingBeforeAdvice.java
package tome.sample.Advisor; import java.lang.reflect.Method; import org.springframework.aop.MethodBeforeAdvice; /** * 前置增强 * * @author onlyone 2013-4-13 下午08:49:02 */ public class GreetingBeforeAdvice implements MethodBeforeAdvice { public void before(Method method, Object[] args, Object obj) throws Throwable { String clientName = (String) args[0]; System.out.println("-----------begin---------------"); System.out.println("GreetingBeforeAdvice is successfully called! "+obj.getClass().getName() + "." + method.getName()); System.out.println("How are you!" + clientName + "!"); System.out.println("-----------end---------------"); } }
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:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <!-- 普通方法名匹配切面 --> <bean id="waiterTarget" class="tome.sample.Advisor.Waiter" /> <bean id="sellerTarget" class="tome.sample.Advisor.Seller" /> <bean id="greetingAdvice" class="tome.sample.Advisor.GreetingBeforeAdvice" /> <bean id="greetingAdvisor" class="tome.sample.Advisor.GreetingAdvisor"> <property name="advice" ref="greetingAdvice" /> </bean> <bean id="parent" abstract="true" class="org.springframework.aop.framework.ProxyFactoryBean" p:interceptorNames="greetingAdvisor" p:proxyTargetClass="true" /> <bean id="waiter" parent="parent"> <property name="target" ref="waiterTarget" /> </bean> <bean id="seller" parent="parent"> <property name="target" ref="sellerTarget" /> </bean> </beans>
测试类
package tome.sample.Advisor; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * 测试类 * * @author onlyone 2013-4-13 下午08:59:36 */ public class TestAdvisor { public static void main(String[] args) { String configPath = "beans.xml"; ApplicationContext ctx = new ClassPathXmlApplicationContext(configPath); Waiter waiter = (Waiter) ctx.getBean("waiter"); Seller seller = (Seller) ctx.getBean("seller"); waiter.greetTo("Tom"); waiter.serveTo("Tom"); seller.greetTo("Tom"); } }
运行结果:
-----------begin--------------- GreetingBeforeAdvice is successfully called! tome.sample.Advisor.Waiter.greetTo How are you!Tom! -----------end--------------- waiter greet to Tom! waiter serving Tom! seller greet to Tom!