#import "AsyncCacheRequestExample.h"
@implementation AsyncCacheRequestExample
- (id)initWithExampleInterface:(ExampleInterface *)exampleInterface {
self = [super initWithExampleInterface:exampleInterface];
self.name = @"AsyncCacheRequest";
self.description =
@"Demonstrates how to create a cache session and send an "
@"asynchronous cache request";
[self.parameters addParameter:PARAMETER_DESTINATION_TOPIC];
[self.parameters addParameter:PARAMETER_CACHE_NAME];
return self;
}
- (void)cacheEventCallbackWithSession:
userData:(void *)user_p {
"cacheEventCallbackWithSession:eventInfo:userData: called: \n"
"\tevent: %s\n"
"\ttopic: %s\n"
"\tresponseCode: (%d) %s\n"
"\tsubCode: (%d) %s\n"
"\tcacheRequestId: %llu\n\n",
eventInfo_p->
topic, eventInfo_p->
rc,
switch (eventInfo_p->
rc) {
"event=SOLCACHE_EVENT_REQUEST_"
"COMPLETED_NOTICE,rc=SOLCLIENT_"
"OK") break;
switch (eventInfo_p->subCode) {
"received event=SOLCACHE_EVENT_REQUEST_COMPLETED_NOTICE,"
"rc=SOLCLIENT_INCOMPLETE, subCode=%s",
break;
"received event=SOLCACHE_EVENT_REQUEST_COMPLETED_NOTICE,"
"rc=SOLCLIENT_INCOMPLETE, subCode=%s",
break;
"received event=SOLCACHE_EVENT_REQUEST_COMPLETED_NOTICE,"
"rc=SOLCLIENT_INCOMPLETE, subCode=%s",
break;
default:
"received event=SOLCACHE_EVENT_REQUEST_COMPLETED_NOTICE,"
"rc=SOLCLIENT_INCOMPLETE, with unusual subcode subCode=%d",
break;
}
break;
"received "
"event=SOLCACHE_EVENT_REQUEST_"
"COMPLETED_NOTICE,rc=SOLCLIENT_"
"FAIL") break;
default:
"with unusual rc=%d",
eventInfo_p->rc);
break;
}
break;
default:
"received unusual event=%d for cache",
eventInfo_p->cacheEvent);
break;
}
}
- (void)run {
[super run];
const char *cacheProps[20];
int propIndex = 0;
callbackBridge_t bridge;
[self handleErrorWithReturnCode:rc
errorString:"solClient_initialize()"];
goto notInitialized;
}
[self setLoggingLevel];
SOLCLIENT_LOG_NOTICE,
"AsyncCacheRequestExample.m (Copyright 2009-2024 Solace Corporation. All rights reserved.)\n");
[self logCCSMPVersion];
&contextFuncInfo,
sizeof(contextFuncInfo))) !=
SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_context_create()"];
goto cleanup;
}
if ((rc = [self
createAndConnectSessionWithContext:context_p
session:&session_p
messageCallback:messageReceivePrintMsgCallback
eventCallback:eventCallback]) !=
[self handleErrorWithReturnCode:
rc errorString:"createAndConnectSessionWithContext:session:"
"messageCallback:eventCallback:userData:"];
goto cleanup;
}
if ((rc = [self
publishMessageWithSession:
session_p topic:(char *)
[[self.parameters
parameterWithId:PARAMETER_DESTINATION_TOPIC]
.value
cStringUsingEncoding:NSASCIIStringEncoding]
[self
handleErrorWithReturnCode:
rc errorString:"publishMessageWithSession:topic:deliveryMode:"];
goto sessionConnected;
}
propIndex = 0;
cacheProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_CACHE_NAME].value
cStringUsingEncoding:NSASCIIStringEncoding];
cacheProps[propIndex] = NULL;
(const char *const *)cacheProps, session_p, &cacheSession_p)) !=
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_createCacheSession"];
goto sessionConnected;
}
solClient_log(SOLCLIENT_LOG_NOTICE,
"Sending cache request.\n\n");
bridge.example_p = (__bridge void *)self;
bridge.user_p = &session_p;
cacheSession_p,
[[self.parameters parameterWithId:PARAMETER_DESTINATION_TOPIC]
.value cStringUsingEncoding:NSASCIIStringEncoding],
cacheRequestId, cacheEventCallback, &bridge, cacheFlags, 0)) !=
[self handleErrorWithReturnCode:
rc errorString:"solClient_cacheSession_sendCacheRequest()"];
goto cleanupCache;
}
"Waiting for cache response. Sleeping for 11 seconds.\n\n");
for (int i = 0; i < 11 && !self.requestCancel; i++) {
[NSThread sleepForTimeInterval:1];
}
cleanupCache:
[self handleErrorWithReturnCode:rc
errorString:"solClient_cacheSession_destroy()"];
}
sessionConnected:
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_disconnect()"];
}
cleanup:
[self handleErrorWithReturnCode:rc errorString:"solClient_cleanup()"];
}
notInitialized:
[self cleanup];
}
@end