ChronicleQueue - Unable to cleanup older CQ4 files - chronicle-queue

I am using CronicleQueue and I have only one writer/reader. Wanted to cleanup as soon as the reader is done with a CQ4 file. The following code wasn't able to remove the file, is the file reference still held by CQ during onReleased() event?
public class ChronicleFactory {
public SingleChronicleQueue createChronicle(String instance, String persistenceDir, RollCycles rollCycles) {
SingleChronicleQueue chronicle = null;
String thisInstance = instance;
try {
chronicle = SingleChronicleQueueBuilder.binary(persistenceDir).rollCycle(rollCycles).storeFileListener(new StoreFileListener() {
#Override
public void onReleased(int i, File file) {
String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy??-MM-dd HH:mm:ss.SSS"));
System.out.println(instance + "> " + currentTime + ": " + Thread.currentThread().getName() + " onReleased called for file: " + file.getAbsolutePath() + " for cycle: " + i);
if(instance.equals("Reader")) {
System.out.println("Removing previous CQ file: " + file.getName() + ", deleted? " + file.delete()); //==> Not able to delete the file !!!
}
}
.....

Don't know whether this is an optimal solution, please let me know if there is a cleaner way, but the following works [except it will have to loop few times before deleting, as the file is actually released after few milliseconds it seems, i see "file is closed" printed few time before the actual delete happens)
#Override
public void onAcquired(int cycle, File file) {
String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy‌​-MM-dd HH:mm:ss.SSS"));
System.out.println(instance + "> " + currentTime + ": " + Thread.currentThread().getName() + " onAcquired called for file: " + file.getAbsolutePath() + " for cycle: " + cycle);
if(prevCycleFile != null && instance.equals("Reader")) {
System.out.println(">>> Trying to remove: " + prevCycleFile);
boolean bDelete;
while((bDelete=prevCycleFile.delete())==false) {
System.out.println(">>> file is closed");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println(">>> Removing previous CQ file: " + prevCycleFile.getAbsolutePath() + ", deleted? " + bDelete);
}
}

It's reasonable to expect a small delay between the Queue reporting that a file is released, and the OS actually detecting/acting upon it.
The StoreFileListener is invoked on the same thread that is reading or writing to the queue, so you will incur latency while the while loop is executing. You'll get better results by handing off the work of closing files to another thread (e.g. via a j.u.c.ConcurrentLinkedQueue).

Related

Is there any way to message on whatsapp without opening the application

I've been searching for the solution to send the message on whatsapp from the Application or via REST-APIs without opening it.
As I have mentioned below the code will validate for the Whatsapp-type installed in device and then it will send it to user but in this case it launch the whatsapp.
private void launchWhatsapp(String msg) {
try {
boolean installed2 = obj.appInstalledOrNot("com.whatsapp.w4b");
if (installed2) try {
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.setPackage("com.whatsapp.w4b");
String url = "https://api.whatsapp.com/send?" +
"phone=" + PhoneNumberUtils.stripSeparators(Cust_Phone_Code + " " + getIntent().getStringExtra("Cust_Mob")) +
"&text=" + msg;
sendIntent.setData(Uri.parse(url));
if (sendIntent.resolveActivity(this.getPackageManager()) != null) {
startActivityForResult(sendIntent, 104);
}
} catch (Exception e) {
e.printStackTrace();
}
else {
boolean installed = obj.appInstalledOrNot("com.whatsapp");
if (installed) {
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.setPackage("com.whatsapp");
String url = "https://api.whatsapp.com/send?" +
"phone=" + PhoneNumberUtils.stripSeparators(Cust_Phone_Code + " " + getIntent().getStringExtra("Cust_Mob")) +
"&text=" + msg;
sendIntent.setData(Uri.parse(url));
if (sendIntent.resolveActivity(this.getPackageManager()) != null) {
startActivityForResult(sendIntent, 104);
}
} else {
Toast.makeText(InvoiceReport.this, "Whatsapp not available", Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
//Log.e("Error", "ERROR_OPEN_MESSANGER"+e.toString());
}
}
I am expecting if anyone click on the browser on send message then this redirect to whatsapp application.

How to use Quarkus to read data from Redis Stream?

Am trying to read data from Redis stream using Quarkus. But am unable to achieve it.Upon checking the Quarkus guide,stream is not available yet .Is there any other way that I could read data from Redis Stream using Quarkus
Using Redis API
#Startup
void onStart(#Observes StartupEvent ev) {
System.out.println("Stream");
Redis.createClient(vertx)
.connect()
.onSuccess(connection -> {
// use the connection
System.out.println("Successfully connected = " + connection + " " + Thread.currentThread().getName());
connection.handler(message -> {
// do whatever you need to do with your message
System.out.println("Message = " + message + " " + Thread.currentThread().getName());
});
connection.send(Request.cmd(Command.XRANGE).arg("test").arg("-").arg("+"))
.onSuccess(res -> {
System.out.println("Subscribed");
System.out.println(res);
});
});
}

Scrapinghub/Splash website page fetching time increasing exponentially with parellel thread

In my trial, I hit splash instance with 50 parallel threads. Each thread will get the page source of the URL. My splash instance default slots value is 50. Here, website fetching time increases exponentially with the number of parallel threads. I can get the perfect HTML source for 50 URLs. But the time increases from 2 seconds to 45 seconds from 1st URL to 50th URL respectively. Please help me to reduce the time for fetching the page source.
My sample java code is
public class SplashThread implements Runnable {
private static final String splash ="http://localhost:8050/execute";
private String script = URLEncoder.encode("function main(splash, args) \n" +
"splash:go(args.url)\n"+
" splash.images_enabled = false\n" +
" splash:on_request(function(request)\n" +
" if string.find(request.url, \".css\")~= nil then\n" +
" request.abort()\n" +
" end\n" +
"end)\n" +
"local html = splash:html()\n" +
"return html\n"+
"end","UTF-8");
private String url =null;
public SplashThread(String url) throws UnsupportedEncodingException {
this.url = url;
}
#Override
public void run() {
HttpClientUtil clientUtil =null;
JSONObject json =null;
try {
Properties queryParms = new Properties();
queryParms.put("url",url);
queryParms.put("timeout","85.0");
queryParms.put("lua_source",script);
clientUtil = new HttpClientUtil(-1,false);
HttpResponse response = clientUtil.doGet(splash,queryParms,null);
String resp = ScrapyUtil.getResponseString(response,"UTF-8");
}
catch (Exception e){
e.printStackTrace();
System.out.println("JSN}ON :: "+json);
}
finally {
if(clientUtil!=null){
try {
clientUtil.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
I am scheduling 50 threads of this runnable object with ScheduledExecutorService.
If I am fecthing the page source once by one, It will working perfectly. But I need to fecth concurrently.

SubreportProcessingEventHandler is not firing even without parameters in the subreport

I'm trying to use the subreport component in my main report but does not fire the event SubreportProcessingEventHandler even without any parameter in the sub-report that can generate any errors.
public ActionResult MyReport(DateTime dateReport)
{
var root = Path.GetDirectoryName(this.Server.MapPath("~"));
if (string.IsNullOrEmpty(root))
{
return this.HttpNotFound();
}
var path = Path.Combine(root, "bin\\Reports\\MainReport.rdlc");
if (System.IO.File.Exists(path))
{
this.reportViewer.LocalReport.ReportPath = path;
}
else
{
return this.View("Index");
}
this.LoadData(dateReport);
var reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
var deviceInfo = "<DeviceInfo>" + " <OutputFormat>" + reportType + "</OutputFormat>"
+ " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>"
+ " <MarginTop>0.2in</MarginTop>" + " <MarginLeft>0.4in</MarginLeft>"
+ " <MarginRight>0.4in</MarginRight>" + " <MarginBottom>0.1in</MarginBottom>"
+ "</DeviceInfo>";
Warning[] warnings;
string[] streams;
var renderedBytes = this.reportViewer.LocalReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return this.File(renderedBytes, mimeType);
}
private void LoadData(DateTime dateReport)
{
........
this.reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(this.MySubreportEventHandler);
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("UserDataSet", users.DistinctBy(u => u.UserName)));
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("EluateReportDataSet", radiopharmacyEluateReports));
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("MarkingProtocolReportDataSet", radiopharmacyMarkingProtocolReports));
this.reportViewer.LocalReport.Refresh();
}
public void MySubreportEventHandler(object sender, SubreportProcessingEventArgs e)
{
.....
e.DataSources.Add(new ReportDataSource("RadiopharmaceuticalQualityControlDataSet", radiopharmacyReportQualityControls));
}
I have checked the output and this warning is raised:
Warning: Warnings occurred while executing the subreport ‘Subreport1’. (rsWarningExecutingSubreport)
After more detailed observation, i noticed that subreport really need an parameter that matches with a parameter passed by main report. Without any parameter the subreport just don't work.

The relative virtual path "WebSite3" is not allowed here

Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration("/WebSite3");
My project name is WebSite3, however when i try running the code, i get the relative virtual path "WebSite3"is not allowed here.
Try:
Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration("~");
That should open to the root of your web application.
This is the code I used to test:
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "";
System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
System.Configuration.KeyValueConfigurationCollection appSettings =
rootWebConfig.AppSettings.Settings;
foreach (string key in appSettings.AllKeys)
{
Label1.Text += "Name: " + key + " Value: " + appSettings[key].Value + "<br />" ;
}
}
Which resulted in the following text on my label (Sensitive info blacked out)