杰克逊在处理反序列化映射过程中出现的异常怪异的行为:它抛出一个JsonMappingException,其.getCause()返回异常链的最里面.
//in main
ObjectMapper jsonMapper = new ObjectMapper();
String json = "{\"id\": 1}";
try {
Q q = jsonMapper.readValue(json, Q.class);
} catch (JsonMappingException e) {
System.out.println(e.getCause()); //java.lang.RuntimeException: ex 2
}
//class Q
public class Q {
@JsonCreator
public Q(@JsonProperty("id") int id) {
throw new RuntimeException("ex 0",
new RuntimeException("ex 1",
new RuntimeException("ex 2")));
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我使用jsonMapper.readValue(..)将String映射json到类的实例,Q其构造函数标记为@JsonCreator抛出一个链RuntimeException:"ex 0", "ex 1", "ex 2".当映射失败时,我预计该行将System.out.println(e.getCause());打印出来ex …
假设我有2个表T1,T2如下所示
T1:
bag_id bag_type capacity
------|--------|--------
1 A 500
2 A 300
3 A 100
4 B 200
5 B 100
Run Code Online (Sandbox Code Playgroud)
T2:
item_type item_amount
---------|-----------
A 850
B 300
Run Code Online (Sandbox Code Playgroud)
表中的每个记录T1代表一个包及其容量,这里我有5个包.我想编写一个SQL,将表中的项目分配T2到具有相同类型的每个包中,即结果应该是这样的
bag_id bag_type capacity allocated_amount
------|--------|--------|----------------
1 A 500 500
2 A 300 300
3 A 100 50
4 B 200 200
5 B 100 100
Run Code Online (Sandbox Code Playgroud)
因此,我发现了一些聚合函数,我们称之为allocate()可以产生allocated_amount如上所述的列.我猜想,如果存在,它可能会像这样使用
select
t1.bag_id,
t1.bag_type,
t1.capacity,
allocate(t2.item_amount, t1.capacity)
over (partition …Run Code Online (Sandbox Code Playgroud) 我试图创建一个特征Entity,强制其子类型有2个状态:Transient和Persistent
trait EntityState
trait Transient extends EntityState
trait Persistent extends EntityState
trait Entity[State <: EntityState]
Run Code Online (Sandbox Code Playgroud)
例如,一个子类,class Post[State <: EntityState] extends Entity[State]可以实例化为new Post[Persistent]或new Post[Transient].
接下来,我将Entity根据以下内容添加一些可以调用的特征方法State:
trait Entity[State <: EntityState] {
def id(implicit ev: State <:< Persistent): Long
def persist(implicit ev: State <:< Transient): Entity[Persistent]
}
Run Code Online (Sandbox Code Playgroud)
为了解释,对于任何扩展的类,只有当类处于状态时(即它已保存到数据库并且已经分配了自动生成的id)Entity,id才能调用该方法Persistent.
另一方面,persist只有当类Transient(尚未保存到数据库)时才能调用该方法.该方法persist旨在将调用者类的实例保存到数据库并返回Persistent该类的版本.
现在,问题是我希望返回类型persist是调用者类的返回类型 …
我有 2 个文件
文件 1:
12342015010198765hello
12342015010188765hello
12342015010178765hello
Run Code Online (Sandbox Code Playgroud)
其每一行都包含固定位置的字段,例如,位置13 - 17用于account_id
文件2:
98765
88765
Run Code Online (Sandbox Code Playgroud)
其中包含account_ids的列表。
在 Korn Shell 中,我想从 file1 打印其位置13 - 17与account_idfile2中的一个匹配的行。
我做不到
grep -f file2 file1
Run Code Online (Sandbox Code Playgroud)
因为account_id在 file2 中可以匹配其他位置的其他字段。
我曾尝试在 file2 中使用模式:
^.{12}98765.*
Run Code Online (Sandbox Code Playgroud)
但没有用。
我正在编写一个 Java 应用程序,将带有附加文件的多部分请求发送到一个 API,该 API 帮助我将带有附件的电子邮件发送到指定的电子邮件。
API 已经过 Postman 测试,可以正常发送邮件。请求正文如下图所示。请注意,附加文件是通过使用 Postman 的“选择文件”按钮分配的。
检查 Postman 的请求正文,以下是我在请求中找到的附加文件内容的一部分。
%PDF-1.5
%
1 0 obj
<</Type/Catalog/Pages 2 0 R/Lang(th-TH) /StructTreeRoot 43 0 R/MarkInfo<</Marked true>>>>
endobj
2 0 obj
<</Type/Pages/Count 5/Kids[ 3 0 R 25 0 R 29 0 R 34 0 R 38 0 R] >>
endobj
3 0 obj
<</Type/Page/Parent 2 0 R/Resources<</Font<</F1 5 0 R/F2 7 0 R/F3 9 0 R/F4 14 0 R/F5 20 0 R/F6 23 0 R>>/XObject<</Image19 19 …Run Code Online (Sandbox Code Playgroud) spring multipartform-data character-encoding mime-types postman
我正在 IOS 和 Android 上开发移动应用程序。目前我使用 Firebase Crashlytic 来跟踪应用程序崩溃日志。
我对 Crashlytic 的功能不太满意。例如,当用户报告问题并在特定时间录制应用程序崩溃的视频时,我希望看到该时间附近设备的日志,但这对于 Crashlytic 来说并不容易。
我脑海中弹出一个解决方案,让移动应用程序将崩溃日志发送到我的 AWS SQS 队列,并以某种方式将其传递到 Elasticsearch,以便我可以使用 Kibana 过滤日志。
我想实现这样的事情
retry_send_error=true在内存中设置标志。retry_send_error==true在内存中发现该事件,请尝试再次发送日志。我一直在互联网上寻找一些参考示例,但找不到任何好的示例。所以我怀疑我的解决方案可能有问题。
如果您知道一些与此类似的架构的好例子,或者您知道这个解决方案不那么受欢迎的原因,请帮助建议。
logging android amazon-web-services elasticsearch crashlytics
我正在使用React Native 的React Navigation。我已成功将其配置为处理通用链接,如下所示
// linking.ts
import { APP_ID } from '@env';
const config = {
screens: {
LoginScreen: 'authorize',
RegisterScreen: 'register',
CustomerStack: {
screens: {
OrderDetailScreen: 'customer/order/:orderId',
},
},
},
};
const linking = {
prefixes: [`${APP_ID}://app/`, 'https://example.com/app/'],
config,
};
export default linking;
Run Code Online (Sandbox Code Playgroud)
// App.tsx
import linking from './linking'
const App = () => {
return (
<NavigationContainer linking={linking}> <MyApp /> </NavigationContainer>
)
}
Run Code Online (Sandbox Code Playgroud)
当我按下浏览器中的链接(例如 )时https://example.com/app/customer/order/1234,它会成功打开我的应用程序的订单页面。
我希望能够打开 url(例如https://example.com/app/customer/order/1234 在我的应用程序内部)并让它打开订单页面。我努力了
<Button onPress={() => …Run Code Online (Sandbox Code Playgroud) deep-linking reactjs react-native ios-universal-links react-navigation
我正在写一个Korn shell脚本,我有这样的函数
#!/bin/ksh
myfunc() {
some_command1 || return 1
some_command2 || return 1
...
}
Run Code Online (Sandbox Code Playgroud)
换句话说,我将双管道后跟一个return语句,以便在命令失败时立即返回该函数.
但我也希望它在返回之前打印一些错误信息,我试过了
#!/bin/ksh
myfunc() {
some_command1 || echo "error while doing some_command1"; return 1
some_command2 || echo "error while doing some_command2"; return 1
...
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用,无论some_command1成功还是失败,第一个返回语句总是被执行.
和
#!/bin/ksh
myfunc() {
some_command1 || (echo "error while doing some_command1"; return 1)
some_command2 || (echo "error while doing some_command2"; return 1)
...
}
Run Code Online (Sandbox Code Playgroud)
也不起作用,它似乎只从子进程返回而不是函数并且some_command2无论some_command1是成功还是失败都会被执行.
有没有办法对语句进行分组,echo "error while doing some_command2"; return 1 …
我正在此处阅读 AWS CloudWatch Logs 文档。他们说
\n\n\n归档日志数据 \xe2\x80\x93 您可以使用 CloudWatch Logs 将日志数据存储在高度持久的存储中。CloudWatch Logs 代理可以轻松快速地将轮换和非轮换日志数据从主机发送到日志服务中。然后,您可以在需要时访问原始日志数据。
\n
在定价页面上,他们有
\n\n\n存储(存档)每 GB 0.03 美元
\n
在定价计算器中,他们提到
\n\n\n日志存储/存档(标准日志和出售日志)\n存档的日志量估计为摄取的日志量的 15%(由于压缩)。假设客户选择一 (1) 个月的保留期,则估算存储/归档成本。默认保留设置为 \xe2\x80\x98never expire\xe2\x80\x99。
\n
我试图了解此存档功能的行为,以决定是否需要将日志数据移动到 S3。但我找不到任何进一步的细节。我尝试探索 CloudWatch Logs 页面中的每个按钮和链接,但找不到归档数据的方法,我只能删除它们或编辑它们的保留规则。
\n那么它是怎样工作的?定价计算器中的备注称估计为摄取量的 15%,这是否意味着它始终自动归档 15% 的日志?为什么他们必须在计算中假设保留期设置为 1 个月,否则存档功能的行为是否有所不同?
\n在Oracle 11g中,我有一个表,命名ITEM,其中每个记录被归类到maingroup与subgroup如下:
+-------+---------+----------+
item_id maingroup subgroup
+-------+---------+---------+
1 group1 subgroup1
2 group1 subgroup2
3 group2 subgroup1
4 group2 subgroup2
...
Run Code Online (Sandbox Code Playgroud)
我必须编写一个程序来报告表中的项目数ITEM.报告输出将类似于:
subgroup1 subgroup2 group_total
group1 10 5 15
group2 0 1 1
subgroup_total 10 6 16
Run Code Online (Sandbox Code Playgroud)
为此,我将编写一个SQL来查询数据,然后使用Java重新格式化输出.SQL应该自己生成完整的报告,即我将仅使用Java重新格式化输出而不进行任何计算.所以,我决定SQL的输出应该是这样的:
+--------------+-----------+-----+
maingroup subgroup cnt
+--------------+-----------+-----+
group1 subgroup1 10
group1 subgroup2 5
group1 group_total 15
group2 subgroup1 0
group2 subgroup2 1
group2 group_total 1
subgroup_total subgroup1 10
subgroup_total subgroup2 6
subgroup_total group_total 16
Run Code Online (Sandbox Code Playgroud)
理想情况下,SQL就像这样简单
select maingroup, …Run Code Online (Sandbox Code Playgroud) 下面的Java方法是指以打印数i由nLoopsPerSecond每秒次seconds秒:
public void test(int nLoopsPerSecond, int seconds) {
double secondsPerLoop = 1.0/(double)nLoopsPerSecond;
long startTime = System.currentTimeMillis();
long currentTime;
int i = 0;
while ((currentTime = System.currentTimeMillis()) < startTime + seconds*1000) {
System.out.println(i++);
while (System.currentTimeMillis() < currentTime + secondsPerLoop*1000);
}
}
Run Code Online (Sandbox Code Playgroud)
通过以下电话:
test(1000,1);
Run Code Online (Sandbox Code Playgroud)
我希望这种方法可以做System.out.println(i++);1000次,但我只有63次.
当我尝试使用此代码查看每个循环实际使用的秒数
public void test(int nLoopsPerSecond, int seconds) {
double secondsPerLoop = 1.0/(double)nLoopsPerSecond;
long startTime = System.currentTimeMillis();
long currentTime;
int i = 0;
while ((currentTime = System.currentTimeMillis()) < startTime + …Run Code Online (Sandbox Code Playgroud) 我使用 AWS Elasticsearch 服务 7.1 版及其内置的 Kibana 来管理应用程序日志。Logstash 每天都会创建新索引。我的 Logstash 不时收到有关最大分片限制范围的错误,我必须删除旧索引才能使其再次工作。
我从该文档 ( https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-handling-errors.html ) 中发现,我可以选择增加_cluster/settings/cluster.max_shards_per_node.
所以我通过在 Kibana Dev Tools 中放置以下命令来尝试
PUT /_cluster/settings
{
"defaults" : {
"cluster.max_shards_per_node": "2000"
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到了这个错误
{
"Message": "Your request: '/_cluster/settings' payload is not allowed."
}
Run Code Online (Sandbox Code Playgroud)
有人建议当我尝试更新一些 AWS 不允许的设置时会发生此错误,但此文档 ( https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-supported-es- Operations.html#es_version_7_1 ) 告诉我这cluster.max_shards_per_node是允许列表中的一个。
请建议如何更新此设置。
java ×2
oracle ×2
shell ×2
sql ×2
unix ×2
android ×1
crashlytics ×1
deep-linking ×1
generics ×1
grep ×1
jackson ×1
json ×1
ksh ×1
logging ×1
loops ×1
mime-types ×1
oracle11g ×1
polymorphism ×1
postman ×1
react-native ×1
reactjs ×1
scala ×1
spring ×1
time ×1
types ×1
while-loop ×1