我正在尝试记录HttpServletRequest属性集合的内容.我需要在servlet首次启动时执行此操作,并在servlet完成之前再次执行此操作.我这样做是为了了解一个狡猾且维护不良的servlet.因为我需要尽可能少的影响,servlet过滤器不是一个选项.
所以这就是问题所在.当servlet启动时,我将遍历HttpServletRequest.getAttributeNames()返回的枚举.但是,当我想再次遍历它时,getAttributeNames().hasMoreElements()返回"false"!我找不到任何"重置"枚举的方法.更糟糕的是,即使我使用HttpServletRequest.setAttribute()向集合添加属性,当我调用getAttributeNames().hasMoreElements()时,我仍然得到"false"的结果.
这真的有可能吗?难道真的没有办法不止一次遍历属性名称吗?
根据要求,这是我的代码.这很简单 - 不要以为我做任何有趣的事情.
/**
*
* Returns the contents of the Attributes collection, formatted for the InterfaceTracker loglines
*
*/
@SuppressWarnings("unchecked")
public static String getAttributes(HttpServletRequest request) {
try {
StringBuilder toLog = new StringBuilder();
Enumeration attributeNames = request.getAttributeNames();
while(attributeNames.hasMoreElements()) {
String current = (String) attributeNames.nextElement();
toLog.append(current + "=" + request.getAttribute(current));
if(attributeNames.hasMoreElements()) {
toLog.append(", ");
}
}
return "TRACKER_ATTRIBUTES={"+ toLog.toString() + "}";
}
catch (Exception ex) {
return "TRACKER_ATTRIBUTES={" + InterfaceTrackerValues.DATA_UNKNOWN_EXCEPTION_THROWN + "}";
}
}
Run Code Online (Sandbox Code Playgroud) 所以,我处在一种情况,我想排队一堆HttpServletRequest对象进行异步处理.暂时搁置这是否是一个明智的策略 - 实际上就是在这种情况下,因为我正在尝试改造一个糟糕的遗留系统 - 这是一件危险的事情吗?
我在这里关心的是HttpServletRequest对象是否持有任何有价值的资源或打开连接会导致死锁或资源争用问题.
这里假设我正在实现一个带有doPost()方法的简单servlet,该方法接受HttpServletRequest对象,将其放入LinkedBlockingQueue,然后向用户发送某种股票响应(如301重定向到确认页面).
谢谢!
我想为一个方法使用两个自定义匹配器.基本上,如果我传递方法VALUE_A,我希望它返回RESULT_A,如果我将它传递给VALUE_B,我希望它返回RESULT_B.所以这是一段代码摘录:
class IsNonEmpty extends ArgumentMatcher<Get> {
public boolean matches(Object get) {
//For some reason, this method is called when I assign the IsEmpty matcher to MockHtable.get()
//When this happens, the value of the get argument is null, so this method throws an NPE
return Arrays.equals(((Get) get).getRow(), SERIALIZATION_HELPER.getValidBytes(key));
}
}
class IsEmpty extends ArgumentMatcher<Get> {
public boolean matches(Object get) {
return !(Arrays.equals(((Get) get).getRow(), SERIALIZATION_HELPER.getValidBytes(key)));
}
}
[...]
//This line executes just fine
Mockito.when(mockHTable.get(Mockito.argThat(new IsNonEmpty()))).thenReturn(dbResult);
[...]
//This line calls IsNonEmpty.matches() for some …Run Code Online (Sandbox Code Playgroud) 回到我的 ASP.NET 时代,我使用URLRewriter.NET进行动态 URL 重写。基本上,它是一个 HTTPModule,它根据您定义的规则拦截页面请求并重写 URL,与 MOD_REWRITE 非常相似。但是,它还允许您定义“自定义转换”,这是一个具有单个方法的类,可以即时为您进行 URL 转换。你可以让这个方法访问数据库,访问 Application[] 集合,几乎可以做任何你想做的事情。
在 J2EE 世界中是否有任何等价物?我希望能够动态地重写 URL 并将这种重写委托给一些 Java 代码。我不想只设置静态重写列表。同样,它需要进行实际的 URL 屏蔽,而不是 3XX 重定向。
如果没有任何东西可以做到这一点,我将如何自己构建此功能?
所以我有一个try/finally块.我需要在finally块中执行许多方法.但是,这些方法中的每一个都可以抛出异常.有没有办法确保在没有嵌套的finally块的情况下调用(或尝试)所有这些方法?
这就是我现在所做的,这非常难看:
protected void verifyTable() throws IOException {
Configuration configuration = HBaseConfiguration.create();
HTable hTable = null;
try {
hTable = new HTable(configuration, segmentMatchTableName);
//...
//various business logic here
//...
} finally {
try {
try {
if(hTable!=null) {
hTable.close(); //This can throw an IOException
}
} finally {
try {
generalTableHelper.deleteTable(configuration, segmentMatchTableName); //This can throw an IOException
} finally {
try {
generalTableHelper.deleteTable(configuration, wordMatchTableName); //This can throw an IOException
} finally {
generalTableHelper.deleteTable(configuration, haplotypeTableName); //This can throw an IOException
} …Run Code Online (Sandbox Code Playgroud) java exception-handling exception try-catch-finally try-finally
默认情况下,Hadoop将hadoop.tmp.dir设置为/ tmp文件夹.这是一个问题,因为当你重新启动时,/ tmp会被Linux消灭,导致JobTracker出现这个可爱的错误:
2012-10-05 07:41:13,618 INFO org.apache.hadoop.ipc.Client: Retrying connect to server: localhost/127.0.0.1:8020. Already tried 0 time(s).
...
2012-10-05 07:41:22,636 INFO org.apache.hadoop.ipc.Client: Retrying connect to server: localhost/127.0.0.1:8020. Already tried 9 time(s).
2012-10-05 07:41:22,643 INFO org.apache.hadoop.mapred.JobTracker: problem cleaning system directory: null
java.net.ConnectException: Call to localhost/127.0.0.1:8020 failed on connection exception: java.net.ConnectException: Connection refused
at org.apache.hadoop.ipc.Client.wrapException(Client.java:767)
Run Code Online (Sandbox Code Playgroud)
我发现修复此问题的唯一方法是重新格式化您的名称节点,该节点重建/ tmp/hadoop-root文件夹,当然重新启动时会再次消除该文件夹.
所以我继续创建了一个名为/ hadoop_temp的文件夹,并为所有用户提供了对它的读/写访问权限.然后我在我的core-site.xml中设置了这个属性:
<property>
<name>hadoop.tmp.dir</name>
<value>file:///hadoop_temp</value>
</property>
Run Code Online (Sandbox Code Playgroud)
当我重新格式化我的namenode时,Hadoop似乎很开心,给我这样的信息:
12/10/05 07:58:54 INFO common.Storage: Storage directory file:/hadoop_temp/dfs/name has been successfully formatted.
Run Code Online (Sandbox Code Playgroud)
但是,当我查看/ hadoop_temp时,我注意到该文件夹是空的.然后当我重新启动Hadoop并检查我的JobTracker日志时,我看到了这个:
2012-10-05 08:02:41,988 INFO org.apache.hadoop.ipc.Client: Retrying connect …Run Code Online (Sandbox Code Playgroud) 在我的开发箱上以伪分布式模式运行HBase.Cloudera CDH4.CentOS的.
不知何故,我的HBase安装已完全损坏.我运行了这个命令:
./bin/hbase hbck -repairHoles
并且读数以此结束:
Summary:
-ROOT- is okay.
Number of regions: 1
Deployed on: localhost.localdomain,60020,1340917622717
.META. is okay.
Number of regions: 1
Deployed on: localhost.localdomain,60020,1340917622717
5 inconsistencies detected.
Run Code Online (Sandbox Code Playgroud)
查看此处的文档:
http://hbase.apache.org/book/apbs03.html
它说:如果在这些步骤之后仍然存在不一致,则很可能存在与孤立或重叠区域相关的表完整性问题.
基本上,我没有兴趣挖掘并试图解决这个问题.我想完全核对我的HBase安装并重新开始清新干净.但是,我不想卸载/重新安装,因为我们使用Cloudera,我不想搞乱他们整个奇怪的配置和设置.
有没有办法删除HBase中的所有数据和元数据而不卸载并重新安装?
所以情况就是这样:我创建了一个SetWritable类,它基本上是java.util.Set的包装器,它实现了Writable接口.我有一个HBase表,其中包含一个列族和一列,该列的值是序列化的SetWritable对象.现在,如果我想在集合中添加一个元素,我需要从HBase中提取行,将其反序列化为SetWritable,添加我的元素,序列化SetWritable,然后将其推回HBase.所以这意味着我的映射器和HBase之间有很多通信.由于我正在处理大量数据,这可能会导致我的性能下降.
我想做的只是将新元素发送到HBase,并在HBase服务器上放置一些反序列化SetWritable的代码,添加元素,序列化SetWritable,然后提交它.这可能吗?协处理器能帮忙吗?
另一个想法:我可以为集合中的每个已知元素添加一列,而不是将我的集合序列化为一列.一个缺点:我可能会收集数十万(或数百万)列.这是一个问题吗?
java ×6
hadoop ×3
hbase ×3
servlets ×2
attributes ×1
enumeration ×1
enumerator ×1
exception ×1
hamcrest ×1
hdfs ×1
jakarta-ee ×1
linux ×1
mapreduce ×1
matcher ×1
mocking ×1
mockito ×1
performance ×1
recovery ×1
repair ×1
try-finally ×1
ubuntu ×1
url ×1