Xamarin.iOS SIGSEGV when trying to discover services of a connected BLE peripheral - xamarin

I'm making a BLE cross-platform app in Xamarin, but fail to discover services of a connected peripheral.
Here's the stripped down code from the shared-project, just to be able to reproduce this issue;
internal class BleTransport
{
//Private stuff
private CBCentralManager Central = null;
private CBPeripheral CurrentPeripheral = null;
private bool IsScanning = false;
internal BleTransport ()
{
//Constructor -- initialize everything that needs to be initialized!
Central = new CBCentralManager (DispatchQueue.MainQueue);
//Setup delegates to the central's events
Central.UpdatedState += (object sender, EventArgs e) => CentralStateChanged.Set ();
Central.DiscoveredPeripheral += (object sender, CBDiscoveredPeripheralEventArgs e) => DiscoveredPeripheral (e.Peripheral, e.RSSI, e.AdvertisementData);
Central.ConnectedPeripheral += (object sender, CBPeripheralEventArgs e) => ConnectedPeripheral (e.Peripheral);
Central.FailedToConnectPeripheral += (object sender, CBPeripheralErrorEventArgs e) => FailedToConnectPeripheral (e.Error, e.Peripheral);
Central.DisconnectedPeripheral += (object sender, CBPeripheralErrorEventArgs e) => DisconnectedPeripheral (e.Error, e.Peripheral);
}
readonly AutoResetEvent CentralStateChanged = new AutoResetEvent (false);
private async Task<bool> WaitForCentralState (CBCentralManagerState state, TimeSpan timespan)
{
Console.WriteLine("Waiting for state : " + state);
//TODO; Keep track of time and decrease time-span accordingly
bool timedout = false;
while (!timedout && Central.State != state)
{
timedout = await Task.Run (delegate {
//WaitOne returns false if we timeout
return !CentralStateChanged.WaitOne (timespan);
});
}
//Return true if we made it, amd false if we timedout
return !timedout;
}
private void StartScanning()
{
Console.WriteLine("Start scan requestd!");
if (!IsScanning)
{
//Start!
IsScanning = true;
Console.WriteLine("Kicking scan for peripherals!");
CBUUID[] uuids = null;
Central.ScanForPeripherals (uuids);
}
}
private void StopScanning()
{
Console.WriteLine("Stop scan requested!");
if (IsScanning)
{
//Stop!
IsScanning = false;
Central.StopScan();
}
}
public async Task<bool> SetupTransport ()
{
Console.WriteLine("Setting up transport!");
//Wait for state update...
if (!await WaitForCentralState (CBCentralManagerState.PoweredOn, TimeSpan.FromSeconds (2))) {
//Failed detecting a powered-on BLE interface
Console.WriteLine("Failed detecting usable BLE interface!");
return false;
}
//Kick scanning...
StartScanning();
//Wait for discovery and connection to a valid peripheral, or timeout trying...
await Task.Delay(10000);
return true;
}
#region Internal BLE utility methods
private void DiscoveredPeripheral (CBPeripheral peripheral, NSNumber rssi, NSDictionary advertisementData)
{
Console.WriteLine("DiscoveredPeripheral: " +peripheral.Name);
//If the discovered device's name IS a valid serial number, AND match the serial number that we're intended to establish connection to...
if (peripheral.Name == "MyPeripheralName") {
Console.WriteLine("It's the peripheral we're looking for!");
//Stop scanning...
StopScanning();
//Save reference and connect to it!
CurrentPeripheral = peripheral;
Central.ConnectPeripheral(CurrentPeripheral, new PeripheralConnectionOptions());
}
}
private void ConnectedPeripheral (CBPeripheral peripheral)
{
Console.WriteLine("ConnectedPeripheral: " + peripheral.Name);
//Great -- explore services and charateristics and don't stop until we know that this device is legit!
CurrentPeripheral.DiscoveredService += (object sender, NSErrorEventArgs e) => DiscoveredServices (e.Error);
CurrentPeripheral.DiscoveredCharacteristic += (object sender, CBServiceEventArgs e) => DiscoveredCharacteristics (e.Error, e.Service);
//Kick service discovery!
CurrentPeripheral.DiscoverServices();
}
private void FailedToConnectPeripheral (NSError error, CBPeripheral peripheral)
{
Console.WriteLine("FailedToConnectPeripheral: " + peripheral.Name);
}
private void DisconnectedPeripheral (NSError error, CBPeripheral peripheral)
{
Console.WriteLine("DisconnectedPeripheral: " + peripheral.Name + "(Error = " + error + ")");
}
private void DiscoveredServices (NSError error)
{
Console.WriteLine("DiscoveredService: " + error + " -- " + NSThread.Current.IsMainThread);
if (error != null) {
//No error -- great!
foreach (CBService service in CurrentPeripheral.Services) {
Console.WriteLine ("Discovered service: " + service);
}
}
else
{
//Opps -- failed!
//Disconnect and indicate connection attempt finished
}
}
private void DiscoveredCharacteristics (NSError error, CBService service)
{
Console.WriteLine("DiscoveredCharacteristics for service: " + service);
if (error != null) {
//No error -- great!
foreach (CBCharacteristic characteristic in service.Characteristics) {
Console.WriteLine ("Discovered charateristic: " + characteristic);
}
}
else
{
//Opps -- failed!
//Disconnect and indicate connection attempt finished
}
}
#endregion
}
The problem is that AFTER discovery is done, scanning is stopped, and the app connect to the peripheral and we arrive in the ConnectedPeripheral (CBPeripheral peripheral) function, I get a SIGSEGV crash with the following stack trace;
2015-04-21 23:33:37.205 BLE-test[1487:322866] critical: Stacktrace:
2015-04-21 23:33:37.206 BLE-test[1487:322866] critical: at <unknown> <0xffffffff>
2015-04-21 23:33:37.206 BLE-test[1487:322866] critical: at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0xffffffff>
2015-04-21 23:33:37.207 BLE-test[1487:322866] critical: at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
2015-04-21 23:33:37.207 BLE-test[1487:322866] critical: at UIKit.UIApplication.Main (string[],string,string) [0x0001c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:45
2015-04-21 23:33:37.208 BLE-test[1487:322866] critical: at BLEtest.Application.Main (string[]) [0x00008] in /Users/markus/Xamarin/BLE-test/BLE-test/Main.cs:17
2015-04-21 23:33:37.208 BLE-test[1487:322866] critical: at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
Followed by a native stack-trace that I've symbolicated into;
Incident Identifier: DCFCEE70-3D12-4F69-8303-777B2959563D
CrashReporter Key: 25c23a5bf636eb183168b18867096174f0d59b79
Hardware Model: iPhone6,2
Process: BLE-test [1241]
Path: /private/var/mobile/Containers/Bundle/Application/C091012A-B1CB-464B-BDA5-B193C9C26BFC/BLE-test.app/BLE-test
Identifier: com.your-company.BLEtest
Version: 1.0 (1.0)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
Date/Time: 2015-04-21 22:22:57.387 +0200
Launch Time: 2015-04-21 22:22:56.120 +0200
OS Version: iOS 8.3 (12F70)
Report Version: 105
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000000004b2c0
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x0000000195233270 __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001952d116c pthread_kill + 108
2 libsystem_c.dylib 0x00000001951aab14 abort + 108
3 BLE-test 0x00000001001f6878 mono_handle_native_sigsegv (mini-exceptions.c:2360)
4 BLE-test 0x0000000100200554 mono_sigsegv_signal_handler (mini.c:6879)
5 libsystem_platform.dylib 0x00000001952c8958 _sigtramp + 64
6 libobjc.A.dylib 0x0000000194aa5ea8 _class_getVariable + 160
7 libobjc.A.dylib 0x0000000194aa5ea8 _class_getVariable + 160
8 libobjc.A.dylib 0x0000000194a9a934 object_getInstanceVariable + 72
9 BLE-test 0x00000001002b10b0 get_raw_gchandle (runtime.m:304)
10 BLE-test 0x00000001002b1044 get_gchandle (runtime.m:311)
11 BLE-test 0x00000001002b0c6c xamarin_get_gchandle (runtime.m:317)
12 BLE-test 0x00000001002b0bc0 xamarin_get_nsobject_with_type_for_ptr_created (runtime.m:201)
13 BLE-test 0x00000001002b9508 xamarin_trampoline (.monotouch-trampoline-setup-callstack.inc:181)
14 CoreBluetooth 0x0000000182f37198 -[CBPeripheral handleServicesDiscovered:] + 740
15 CoreBluetooth 0x0000000182f34b38 -[CBPeripheral handleMsg:args:] + 280
16 CoreBluetooth 0x0000000182f309d0 -[CBCentralManager xpcConnection:didReceiveMsg:args:] + 160
17 libdispatch.dylib 0x00000001950ed990 _dispatch_call_block_and_release + 20
18 libdispatch.dylib 0x00000001950ed950 _dispatch_client_callout + 12
19 libdispatch.dylib 0x00000001950f80a0 _dispatch_queue_drain + 1444
20 libdispatch.dylib 0x00000001950f0a58 _dispatch_queue_invoke + 128
21 libdispatch.dylib 0x00000001950f1db8 _dispatch_main_queue_callback_4CF + 500
22 CoreFoundation 0x000000018327f7f4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
23 CoreFoundation 0x000000018327d89c __CFRunLoopRun + 1488
24 CoreFoundation 0x00000001831a92d0 CFRunLoopRunSpecific + 392
25 GraphicsServices 0x000000018c9c76f8 GSEventRunModal + 164
26 UIKit 0x0000000187d6efa8 UIApplicationMain + 1484
27 BLE-test 0x00000001000a0b94 wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 340
28 BLE-test 0x000000010007e60c UIKit_UIApplication_Main_string___intptr_intptr + 44
29 BLE-test 0x000000010007e5c8 UIKit_UIApplication_Main_string___string_string + 184
30 BLE-test 0x0000000100050110 BLEtest_Application_Main_string__ + 160
31 BLE-test 0x000000010017c06c wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 156
32 BLE-test 0x0000000100202614 mono_jit_runtime_invoke (mini.c:6737)
33 BLE-test 0x000000010024d31c mono_runtime_invoke (object.c:2842)
34 BLE-test 0x00000001002513f8 mono_runtime_exec_main (object.c:4099)
35 BLE-test 0x00000001002afa34 xamarin_main (monotouch-main.m:400)
36 BLE-test 0x00000001001ca924 main + 92
37 libdyld.dylib 0x000000019511aa04 start + 0
Observations and thoughts;
If I remove the delegates to the peripheral after it has been connected, but before I try to discover its services (which means that I'll never see the result of the discovery, but just for test), the DiscoverService routine does NOT result in a crash;
// CurrentPeripheral.DiscoveredService += (object sender, NSErrorEventArgs e) => ...
// CurrentPeripheral.DiscoveredCharacteristic += (object sender, ...
Likewise, I've also tried to keep the delegates above, but remove the actual call to DiscoverServices and that also work without crashing (which is again a stupid test perhaps, but I just wanted to rule-out that something happened when I assigned the delegates in the first place).
I've also read about other peoples experiences with these kind of issues/errors and someone said that it's a GC-issue where an object might be GC'd even though it's still referenced?
Someone also mentioned that things worked in Release-mode but not in debug mode -- so I've tested to run my app in release which ALSO seems to work -- but I don't have any UI so I can't guarantee that is actually works -- but I do know that it does not crash with SIGSEGV...
I'm confused. Please help me understand why Xamarin does not like me. I'm happy to adjust and play by the Xamarin-rules, as long as I understand the constraints and what I can/can't do.
UPPDATE;
I just tried to see if the error was the callback/event-handlers inside the
CBPeripheral, or the actual DiscoverServices method call. So I tried to call
the function and wait 500ms and then see if the services had been discovered in
my peripheral object;
Console.WriteLine ("List of services (before discovery attempt)");
if (CurrentPeripheral.Services != null)
foreach (CBService service in CurrentPeripheral.Services) {
Console.WriteLine ("Service: " + service);
}
CurrentPeripheral.DiscoverServices();
await Task.Delay(500);
Console.WriteLine ("List of services (after discovery attempt)");
if (CurrentPeripheral.Services != null)
foreach (CBService service in CurrentPeripheral.Services) {
Console.WriteLine ("Service: " + service);
}
... and it works! Hence, this means that the call to DiscoverServices works
just fine, but the callbacks does not!

Ok, problem solved. A newbie thing, of course...
When I launched Xamarin Studio and started this project, I played around and looked at the different options, settings, features, menus etc, just to get a grip of the concept as such. One of the things I found was the iOS-build options where one could change the Linker Options. I figured that "Link all assemblies" was a good choice, just to be on the safe side, rather than "Don't link" which was preselected.
Didn't think more about it and continued with the coding.
But when I found the issue raised and explain in this thread, you desperately start to search for anything anywhere, and I started to hunt for GC issues which was what thought was the source of the error. So, reading through the best-practices for Memory management at this link (http://developer.xamarin.com/guides/cross-platform/deployment,_testing,_and_metrics/memory_perf_best_practices/), I found that;
The Link All Assemblies should be used with caution as it may break the application in unexpected ways.
Hence, I changed back to Don't link and now everything works like a charm...
Stuped newbie error? Yes, for sure, but I hope that someone else making the same misstake will find this post and find it useful.
Thanks,
/Markus

Related

Xamarin.forms ios MonoTouchException on Navigation.RemovePage

In my xamarin.forms ios application I have 4 ContentPages and 1 Popup(Rg.Plugin)
My Navigation is like this
Page 1--> Page 2 --> Page 3 --> Page 4 --> Popup
I want to navigate to Page 1 from a button click in Popup by removing the pages(2,3,4 and Popup).
I done it like this.
private void OK_Clicked(object sender, EventArgs e)
{
try
{
var countPagesToRemove = 3;
var mainPage = (Application.Current.MainPage as NavigationPage);
for (var i = 1; i < countPagesToRemove; i++)
{
mainPage.Navigation.RemovePage(mainPage.Navigation.NavigationStack[mainPage.Navigation.NavigationStack.Count - 2]);
}
Navigation.PopAsync();
Task.Delay(5);
PopupNavigation.Instance.PopAsync();
}
catch (Exception ex)
{
DisplayAlert("Result", ex.Message, "ok");
}
}
This works perfectly on Android.In ios it throws me this exception.
Foundation.MonoTouchException
Message=Objective-C exception thrown. Name: CALayerInvalidGeometry Reason: CALayer bounds contains NaN: [0 0; 0 nan]
Native stack trace:
Source=Xamarin.iOS
StackTrace:
at ObjCRuntime.Runtime.ThrowNSException (System.IntPtr ns_exception) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.39/src/Xamarin.iOS/ObjCRuntime/Runtime.cs:406
at ObjCRuntime.Runtime.throw_ns_exception (System.IntPtr exc) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/runtime/Delegates.generated.cs:128
at (wrapper native-to-managed) ObjCRuntime.Runtime.throw_ns_exception(intptr)
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.39/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.39/src/Xamarin.iOS/UIKit/UIApplication.cs:65
I have no idea what does this mean. I have searched and many people got this issues in several situations.But I didn't something like my scenerio.How to solve this?Any help is appreciated.

BlockingQueue vs PipedOutputStream and PipedInputStream

I want to know Advantages to use BlockingQueue instead of (PipedOutputStream and PipedInputStream)
import java.io.*;
import java.util.concurrent.*;
public class PipedStreamVsBlocking {
public static void main(String... args) {
BlockingQueue<Integer> blockingQueue = new LinkedBlockingDeque<>(2);
ExecutorService executor = Executors.newFixedThreadPool(4);
Runnable producerTask = () -> {
try {
while (true) {
int value = ThreadLocalRandom.current().nextInt(0, 1000);
blockingQueue.put(value);
System.out.println("BlockingQueue.Produced " + value);
int timeSleeping = ThreadLocalRandom.current().nextInt(500, 1000);
Thread.sleep(timeSleeping);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
};
Runnable consumerTask = () -> {
try {
while (true) {
int value = blockingQueue.take();
System.out.println("BlockingQueue.Consume " + value);
int timeSleeping = ThreadLocalRandom.current().nextInt(500, 1000);
Thread.sleep(timeSleeping);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
};
PipedOutputStream pipedSrc = new PipedOutputStream();
PipedInputStream pipedSnk = new PipedInputStream();
try {
pipedSnk.connect(pipedSrc);
} catch (IOException e) {
e.printStackTrace();
}
Runnable runnablePut2 = () -> {
try {
ObjectOutputStream oos = new ObjectOutputStream(pipedSrc);
while (true) {
int value = ThreadLocalRandom.current().nextInt(0, 1000);
oos.writeInt(value);
oos.flush();
System.out.println("PipedStream.Produced " + value);
int timeSleeping = ThreadLocalRandom.current().nextInt(500, 1000);
Thread.sleep(timeSleeping);
}
} catch (Exception e) {
e.printStackTrace();
}
};
Runnable runnableGet2 = () -> {
try {
ObjectInputStream ois = new ObjectInputStream(pipedSnk);
while (true) {
int value = ois.readInt();
System.out.println("PipedStream.Consume " + value);
int timeSleeping = ThreadLocalRandom.current().nextInt(500, 1000);
Thread.sleep(timeSleeping);
}
} catch (Exception e) {
e.printStackTrace();
}
};
executor.execute(producerTask);
executor.execute(consumerTask);
executor.execute(runnablePut2);
executor.execute(runnableGet2);
executor.shutdown();
}
}
The output for this code is:
BlockingQueue.Consume 298
BlockingQueue.Produced 298
PipedStream.Produced 510
PipedStream.Consume 510
BlockingQueue.Produced 536
BlockingQueue.Consume 536
PipedStream.Produced 751
PipedStream.Consume 751
PipedStream.Produced 619
BlockingQueue.Produced 584
BlockingQueue.Consume 584
PipedStream.Consume 619
BlockingQueue.Produced 327
PipedStream.Produced 72
BlockingQueue.Consume 327
PipedStream.Consume 72
BlockingQueue.Produced 823
BlockingQueue.Consume 823
PipedStream.Produced 544
PipedStream.Consume 544
BlockingQueue.Produced 352
BlockingQueue.Consume 352
PipedStream.Produced 134
PipedStream.Consume 134
I think that to use PipedStream (PipedOutputStream and PipedInputStream) have advantages, I know when the data is produced/Processed directly.
May be I wrong, And this recommendation to use BlockingQueue instead of Pipe.
But, your comments/recommendations are not found in the documentation.
For this reason, I need to know what I missed.
Why should I use BlockingQueue instead of Piped?
Like any Java Collection, a BlockingQueue stores references to objects, so the thread(s) retrieving objects from it receive precisely the same runtime objects, the producing thread(s) put into it.
In contrast, Serialization stores a persistent form into the byte stream, which only works for Serializable objects and will lead to the creation of copies at the receiving end. In some cases, the objects may get replaced by canonical objects afterwards, still, the entire procedure is significantly more expensive than just transferring references.
In your example case, where you transfer int values, the object identity doesn’t matter, but the overhead of boxing, serializing, deserializing, and unboxing Integer instances is even more questionable.
If you didn’t use Serialization, but transferred int values as four byte quantities directly, using PipedOutputStream and PipedInputStream had a point, as it is a good tool for transferring large quantities of primitive data. It also has an intrinsic support for marking the end of data by closing the pipe.
These pipes would also be the right tool for software that ought to be agnostic regarding processes or even the computers running the producer or consumer, i.e. when you want to be able to use the same software when the pipe is actually between processes or even a network connection. That would also justify using Serialization (as JMX connections do).
But unless you’re truly transferring single bytes that retain their meaning when being torn apart, there’s the intrinsic limitation that only one producer can write into a pipe and only one consumer can read the data.

Async IO operation failed (1), reason: RC: 32 Broken pipe IN SPRING mvc rest service

How to set connection timeout to only particular to that rest spring mvc request.
I want to render huge data of clothes on browser but server send an connection timeout error.
#RequestMapping(value="/clothes/{clothType}/properties", method = RequestMethod.GET)
public #ResponseBody List<Clothes> getClothesList(#PathVariable String clothType, HttpServletResponse response) {
List<Clothes> listClothes;
try {
listClothes = ClothesApiService.getClothesProperties(clothType);
} catch (Exception e) {
log.info("Problem getting the properties for Clothes " + clothType + ". Error: " + e.getMessage());
}
return listClothes;
}
Below is stack trace on IBM server logs
at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1613) ~[jackson-all-1.9.11.jar:1.9.11]
128 at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:140) ~[org.springframework.web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
129 ... 49 common frames omitted
130 Caused by: java.io.IOException: Async IO operation failed (1), reason: RC: 32 Broken pipe
131 at com.ibm.io.async.AsyncLibrary$IOExceptionCache.(AsyncLibrary.java:891) ~[com.ibm.ws.runtime.jar:na]
132 at com.ibm.io.async.AsyncLibrary$IOExceptionCache.get(AsyncLibrary.java:904) ~[com.ibm.ws.runtime.jar:na]
133 at com.ibm.io.async.AsyncLibrary.getIOException(AsyncLibrary.java:918) ~[com.ibm.ws.runtime.jar:na]
134 at com.ibm.io.async.AbstractAsyncChannel.multiIO(AbstractAsyncChannel.java:473) ~[com.ibm.ws.runtime.jar:na]
135 at com.ibm.io.async.AsyncSocketChannelHelper.write(AsyncSocketChannelHelper.java:478) ~[com.ibm.ws.runtime.jar:na]
136 at com.ibm.io.async.AsyncSocketChannelHelper.write(AsyncSocketChannelHelper.java:396) ~[com.ibm.ws.runtime.jar:na]
137 at com.ibm.ws.tcp.channel.impl.AioSocketIOChannel.writeAIO(AioSocketIOChannel.java:282) ~[com.ibm.ws.runtime.jar:na]
138 at com.ibm.ws.tcp.channel.impl.AioTCPWriteRequestContextImpl.processAsyncWriteRequest(AioTCPWriteRequestContextImpl.java:53) ~[com.ibm.ws.runtime.jar:na]
139 at com.ibm.ws.tcp.channel.impl.TCPWriteRequestContextImpl.writeInternal(TCPWriteRequestContextImpl.java:382) ~[na:CC70.CF [a0849.02]]
140 at com.ibm.ws.tcp.channel.impl.TCPWriteRequestContextImpl.write(TCPWriteRequestContextImpl.java:353) ~[na:CC70.CF [a0849.02]]
141 at com.ibm.ws.http.channel.impl.HttpServiceContextImpl.asynchWrite(HttpServiceContextImpl.java:2442) ~[com.ibm.ws.runtime.jar:na]
142 at com.ibm.ws.http.channel.impl.HttpServiceContextImpl.sendOutgoing(HttpServiceContextImpl.java:2229) ~[com.ibm.ws.runtime.jar:na]
143 at com.ibm.ws.http.channel.inbound.impl.HttpInboundServiceContextImpl.sendResponseBody(HttpInboundServiceContextImpl.java:866) ~[com.ibm.ws.runtime.jar:na]
144 at com.ibm.ws.webcontainer.channel.WCChannelLink.writeBufferAsynch(WCChannelLink.java:551) [com.ibm.ws.webcontainer.jar:na]
145 at com.ibm.ws.webcontainer.channel.WCChannelLink.writeBufferResponse(WCChannelLink.java:528) [com.ibm.ws.webcontainer.jar:na]
146 at com.ibm.ws.webcontainer.channel.WCChannelLink.writeBuffer(WCChannelLink.java:472) [com.ibm.ws.webcontainer.jar:na]
147 at com.ibm.ws.webcontainer.channel.WCCByteBufferOutputStream.flushWriteBuffer(WCCByteBufferOutputStream.java:406) ~[com.ibm.ws.webcontainer.jar:na]
148 at com.ibm.ws.webcontainer.channel.WCCByteBufferOutputStream.checkWriteArray(WCCByteBufferOutputStream.java:378) ~[com.ibm.ws.webcontainer.jar:na]
149 at com.ibm.ws.webcontainer.channel.WCCByteBufferOutputStream.write(WCCByteBufferOutputStream.java:111) ~[com.ibm.ws.webcontainer.jar:na]
150 at com.ibm.ws.webcontainer.srt.SRTOutputStream.write(SRTOutputStream.java:97) ~[com.ibm.ws.webcontainer.jar:na]
151 at com.ibm.wsspi.webcontainer.util.BufferedServletOutputStream.writeOut(BufferedServletOutputStream.java:569) ~[com.ibm.ws.webcontainer.jar:na]
152 at com.ibm.wsspi.webcontainer.util.BufferedServletOutputStream.flushBytes(BufferedServletOutputStream.java:433) ~[com.ibm.ws.webcontainer.jar:na]
153 at com.ibm.wsspi.webcontainer.util.BufferedServletOutputStream.write(BufferedServletOutputStream.java:383) ~[com.ibm.ws.webcontainer.jar:na]
154 at org.codehaus.jackson.impl.Utf8Generator._flushBuffer(Utf8Generator.java:1754) ~[jackson-all-1.9.11.jar:1.9.11]
155 at org.codehaus.jackson.impl.Utf8Generator.writeString(Utf8Generator.java:561) ~[jackson-all-1.9.11.jar:1.9.11]
156 at org.codehaus.jackson.map.ser.std.StringSerializer.serialize(StringSerializer.java:28) ~[jackson-all-1.9.11.jar:1.9.11]
157 at org.codehaus.jackson.map.ser.std.StringSerializer.serialize(StringSerializer.java:18) ~[jackson-all-1.9.11.jar:1.9.11]
158 at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446) ~[jackson-all-1.9.11.jar:1.9.11]
159 ... 58 common frames omitted
Below is my code
#RequestMapping(value="/clothes/{clothType}/properties", method = RequestMethod.GET)
public #ResponseBody List<Clothes> getClothesList(#PathVariable String clothType, HttpServletResponse response) {
List<Clothes> listClothes;
try {
listClothes = ClothesApiService.getClothesProperties(clothType);
} catch (Exception e) {
log.info("Problem getting the properties for Clothes " + clothType + ". Error: " + e.getMessage());
}
return listClothes;
}

How to reload all tabs at a particular time each day in a Chrome extension

I am trying to write a Chrome extension that can reload all Google Chrome tabs at 7AM. I have to do this every day and it will be nice to have a small program that does it for me. I have tried one of the existing extensions but it's not working correctly for me, so I've taken some existing code and am trying to make it do what I want:
219 updateMonitorSelectors: function () {
220 //p.ex.currentReload.monitor.selectors.length = 0;
221 if (p.v.isInitSelector) return;
222 p.ex.currentReload.monitor.selectors = [];
223 $(p.s.dMonitor_nu + ' input[type="text"]').each(function () {
224 var disabled = $(this).attr('disabled');
225 if (!disabled) {
226 p.ex.currentReload.monitor.selectors[p.ex.currentReload.moni tor.selectors.length] = $(this).val();
227 }
228 });
229 },
230 initControls: function () {
231 if (this.initControls.timerId) clearTimeout(this.initControls.timerI d);
232 if (p.ex.currentReload === null) { this.initControls.timerId = setTi meout('p.initControls()', 250); return; };
233 var reload = p.ex.currentReload;
234 $(p.s.tRandomStartSecs).val(reload.rand.from);
235 $(p.s.tRandomEndMins).val(reload.rand.to / 60);
236 $(p.s.tCustomSecs).val(reload.secs);
237 $(p.s.tDefaultSecs).val(p.ex.defaultTime);
238 if (reload.isTabRefresh) { $(p.s.rTab).attr('checked', 'checked'); }
239 else $(p.s.rUrl).attr('checked', 'checked');
240
241 if (reload.span.isStartOn) {
242 $(p.s.cStart).attr('checked', 'checked');
243 $(p.s.tStart).removeAttr('disabled');
244 $(p.s.tStart).val(p.time.toLocal(reload.span.startTime));
245 }
246 if (reload.span.isEndOn) {
247 $(p.s.cEnd).attr('checked', 'checked');
248 $(p.s.tEnd).removeAttr('disabled');
249 $(p.s.tEnd).val(p.time.toLocal(reload.span.endTime));
250 }
251

request.GetResponse() Timeout

Waker.cs
class Waker
{
Timer timer;
public Waker()
{
timer = null;
}
public void WakeUpApplicationPool(object obj)
{
string url = "http://www.example.com";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Program.LogToFile("WakeUpApplicationPool: " + response.StatusDescription);
response.Close();
}
catch (Exception ex)
{
Program.LogToFile("WakeUpApplicationPool_Error: " + ex.ToString());
}
}
public void Start()
{
TimerCallback callback = new TimerCallback(WakeUpApplicationPool);
int DUE_TIME = 0; //The amount of time to delay before the callback parameter invokes its methods.
int PERIOD = int.Parse(ConfigurationManager.AppSettings["WakerIntervalPeriod"]); //The time interval (miliseconds) between invocations of the methods referenced by callback
timer = new Timer(callback, null, DUE_TIME, PERIOD);
}
public void Stop()
{
timer.Dispose();
}
}
Program.cs:
static void Main(string[] args)
{
try
{
Waker waker = new Waker();
waker.Start();
}
catch(Exception ex)
{
LogToFile(ex.ToString());
}
}
Log file:
15 Apr 2015 18:29:39 - WakeUpApplicationPool: OK
15 Apr 2015 18:31:39 - WakeUpApplicationPool: OK
15 Apr 2015 18:33:59 - WakeUpApplicationPool_Error: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 205.144.171.35:80
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)
15 Apr 2015 18:35:39 - WakeUpApplicationPool: OK
15 Apr 2015 18:37:39 - WakeUpApplicationPool: OK
15 Apr 2015 18:41:18 - WakeUpApplicationPool_Error: System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)
15 Apr 2015 18:43:18 - WakeUpApplicationPool_Error: System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)
15 Apr 2015 18:45:18 - WakeUpApplicationPool_Error: System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)
15 Apr 2015 18:47:18 - WakeUpApplicationPool_Error: System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)
The problem is:
My code is not working after it hit the Timed Out error. But after I restart the Program.exe, it is working again but it hit the Timed Out error after 10 minutes.
I want to use this Program.exe to wake up my application pool which hosted at hosting provider.
So could anyone tell the reason and solution is? I referred this,but it is not working for my code either
The problem is solved after I set the WakerIntervalPeriod to 10 minutes instead of 5 minuets.

Resources