interceptor

Java字节码3-使用ByteBuddy实现一个Java-Agent

眉间皱痕 提交于 2020-02-28 22:06:59
一、概述 在前面两节中,我们实现了Agent,但是其无论在使用方式和功能上面都有一定的局限性。本文我们借助字节码工具ByteBuddy,写出高级的Agent。 ByteBuddy不仅仅是为了生成Java-Agent,它提供的API甚至可以改变重写一个Java类,本文我们使用其API实现和第二节一样的功能,给目标类中的函数统计其调用耗时。 二、实现 1、修改pom.xml 本节和上节的不同点,主要有两个。一个是引入ByteBuddy的依赖,另一个是需要将ByteBuddy的包通过shade打入到Agent中。下面只截取关键代码: <dependency> <groupId>net.bytebuddy</groupId> <artifactId>byte-buddy</artifactId> <version>1.5.7</version> </dependency> <dependency> <groupId>net.bytebuddy</groupId> <artifactId>byte-buddy-agent</artifactId> <version>1.5.7</version> </dependency> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin<

Java字节码3-使用ByteBuddy实现一个Java-Agent

拥有回忆 提交于 2020-02-27 21:20:35
Java字节码系列 Java字节码1-Agent简单上手 Java字节码2-instrument初体验 Java字节码3-使用ByteBuddy实现一个Java-Agent Java字节码4-使用Java-Agent实现一个JVM监控工具 本系列代码可见: https://github.com/hawkingfoo/demo-agent 一、概述 在前面两节中,我们实现了Agent,但是其无论在使用方式和功能上面都有一定的局限性。本文我们借助字节码工具ByteBuddy,写出高级的Agent。 ByteBuddy不仅仅是为了生成Java-Agent,它提供的API甚至可以改变重写一个Java类,本文我们使用其API实现和第二节一样的功能,给目标类中的函数统计其调用耗时。 二、实现 1、修改pom.xml 本节和上节的不同点,主要有两个。一个是引入ByteBuddy的依赖,另一个是需要将ByteBuddy的包通过shade打入到Agent中。下面只截取关键代码: < dependency > < groupId > net.bytebuddy </ groupId > < artifactId > byte-buddy </ artifactId > < version > 1.5.7 </ version > </ dependency > < dependency > <

看懂了责任链模式,你就能明白很多

跟風遠走 提交于 2020-02-27 16:09:47
前言 只有光头才能变强。 文本已收录至我的GitHub精选文章,欢迎Star : https://github.com/ZhongFuCheng3y/3y 最近在看项目代码的时候发现「责任链模式」,于是想花点时间来写写什么是责任链模式。 不知道大家是怎么学习设计模式的,一般我都是用到的时候,或者接触到的时候才会去学。否则感觉学完就很容易就忘掉了,不能理解为什么要使用设计模式(因为没有真实的场景给我去使用)。 在之前我已经更新说几篇设计模式的文章了,我觉得写得「还行」,有兴趣的同学可以到我的 GitHub 上,关键字搜索「 设计模式 」,就能找到对应的文章。 不得不说,我现在负责项目的代码我常常会感叹: 这代码怎么这么骚啊! 项目里边用到了很多的设计模式,在最开始看的时候会很费劲(因为之前没学),但维护起来是真的方便。 一、什么是责任链模式? 在说责任链模式之前,我们先来聊聊「 过滤器 」。 过滤器相信大家都肯定学过了,在最开始学Servlet的时候我们会学到 Filter 。等学到Struts2的时候,我们会学到 Interceptor 。等学到SpringMVC的时候,我们会学到 HandlerInterceptor 。 但无论学哪个框架,我们发现是最终其实它还是做 Filter 这么一件事。说白了就是: 把所有的过滤器都放在 FilterChain 里边,依次执行每个过滤器。

artemis小结

人盡茶涼 提交于 2020-02-27 05:50:04
序 本文主要小结一下artemis的一些知识点 artemis知识点 消息模型 它实现了mqtt、aqmp、stomp协议,jms的api,还提供了rest的api;其模型跟aqmp很像,用address、queue来抽象,其Routing Types有Anycast( point-to-point )、Multicast( publish-subscribe )两种类型 client、server端的flow control 通过credit以及windowSize来控制 client、server端的rebalance client端有ConnectionLoadBalancingPolicy,server端有MessageLoadBalancingType、Redistributor client、server端的interceptor 内置了client、server的interceptor,方便拦截添加边缘逻辑 投递模式:at-most-once、at-least-once、exactly-once exactly-once需要事务支持,不过可以通过服务端去重 消费模型:推、拉、还是推拉结合、ack模式 推拉结合的,同步receive方式就是拉的方式,消费者主动去消息服务器取消息,异步的listener方式为推的方式 特性消息:延迟消息、优先级消息、持久消息、TTL消息

聊聊artemis的BaseInterceptor

徘徊边缘 提交于 2020-02-27 04:52:37
序 本文主要研究一下artemis的BaseInterceptor BaseInterceptor activemq-artemis-master/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/BaseInterceptor.java public interface BaseInterceptor<P> { /** * Intercepts a packet which is received before it is sent to the channel * * @param packet the packet being received * @param connection the connection the packet was received on * @return {@code true} to process the next interceptor and handle the packet, * {@code false} to abort processing of the packet * @throws ActiveMQException */ boolean intercept(P packet, RemotingConnection

0219 springmvc-拦截器和响应增强

旧街凉风 提交于 2020-02-26 17:36:08
拦截器 拦截器分同步拦截器和异步拦截器; HandlerInterceptor 方法和执行时机 可以看DispathcerServlet的原来确定它的三个方法的执行时机; AsynHandlerInterceptor 看注释,主要用来清理在并发环境加清理ThreadLocal的数据; ResponseBodyAdvice 对返回值备注了@ResponseBody或者返回ResponseEntity做了一些加工; 会在使用消息转换器转换为json数据之前进行数据转换输出; package com.springbootpractice.interceptor.config; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.springbootpractice.interceptor.config.interceptor.MyInterceptor; import lombok.SneakyThrows; import org.springframework.context.annotation.Configuration; import org.springframework.core

How to add Api_KEY into interceptor using okhttp

让人想犯罪 __ 提交于 2020-02-24 06:56:24
问题 I have this service where I want to put the token as an interception in the okhttp instead of passing as a parameter with @Header("MY_API_KEY") This is my code regarding the service /** * Provides the [PHService] */ fun provideService(): PHService { val logger = HttpLoggingInterceptor() logger.level = HttpLoggingInterceptor.Level.BASIC val client = OkHttpClient.Builder() .addInterceptor(logger) .build() return Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .client(client)

How to add Api_KEY into interceptor using okhttp

馋奶兔 提交于 2020-02-24 06:56:02
问题 I have this service where I want to put the token as an interception in the okhttp instead of passing as a parameter with @Header("MY_API_KEY") This is my code regarding the service /** * Provides the [PHService] */ fun provideService(): PHService { val logger = HttpLoggingInterceptor() logger.level = HttpLoggingInterceptor.Level.BASIC val client = OkHttpClient.Builder() .addInterceptor(logger) .build() return Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .client(client)

How to add Api_KEY into interceptor using okhttp

為{幸葍}努か 提交于 2020-02-24 06:55:00
问题 I have this service where I want to put the token as an interception in the okhttp instead of passing as a parameter with @Header("MY_API_KEY") This is my code regarding the service /** * Provides the [PHService] */ fun provideService(): PHService { val logger = HttpLoggingInterceptor() logger.level = HttpLoggingInterceptor.Level.BASIC val client = OkHttpClient.Builder() .addInterceptor(logger) .build() return Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .client(client)

File not downloaded with execAndWait Struts Interceptor after inserting delay

 ̄綄美尐妖づ 提交于 2020-02-16 06:57:31
问题 My code downloads a file from back-end server. Since we will be retrieving records numbering in millions, we have used Struts2 execAndWait Interceptor. To test this, we are inserting delay of 30 secs. I am able to download file without inserting delay (where test data very small), but after inserting it, i never get the file. Logs show that action class is being repeatedly executed due to <meta-refresh> of 5 secs in wait file, even input-stream is populated. What could be the reason for such