or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

bean-management.mddatabase-orm.mddatabase-upgrades.mdframework-integration.mdindex.mdlifecycle-events.mdportlet-framework.mdservice-layer.mdtemplate-processing.mdutility-services.mdweb-security.md

lifecycle-events.mddocs/

0

# Lifecycle Events & Actions

1

2

Event-driven system handling portal startup, shutdown, authentication, session management, and service request processing with comprehensive lifecycle hooks and extensibility points.

3

4

## Capabilities

5

6

### Startup and Shutdown Events

7

8

Portal-wide and application-level lifecycle management with comprehensive initialization and cleanup procedures.

9

10

```java { .api }

11

/**

12

* Global portal startup action executed during portal initialization

13

*/

14

public class GlobalStartupAction extends Action {

15

16

/**

17

* Executes global startup procedures

18

* @param request HTTP servlet request

19

* @param response HTTP servlet response

20

* @throws ActionException if startup fails

21

*/

22

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

23

}

24

25

/**

26

* Global portal shutdown action executed during portal termination

27

*/

28

public class GlobalShutdownAction extends Action {

29

30

/**

31

* Executes global shutdown procedures and cleanup

32

* @param request HTTP servlet request

33

* @param response HTTP servlet response

34

* @throws ActionException if shutdown fails

35

*/

36

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

37

}

38

39

/**

40

* Application-level startup action for individual applications

41

*/

42

public class AppStartupAction extends Action {

43

44

/**

45

* Executes application-specific startup procedures

46

* @param request HTTP servlet request

47

* @param response HTTP servlet response

48

* @throws ActionException if startup fails

49

*/

50

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

51

}

52

53

/**

54

* Application-level shutdown action for individual applications

55

*/

56

public class AppShutdownAction extends Action {

57

58

/**

59

* Executes application-specific shutdown procedures

60

* @param request HTTP servlet request

61

* @param response HTTP servlet response

62

* @throws ActionException if shutdown fails

63

*/

64

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

65

}

66

```

67

68

### Startup and Shutdown Utilities

69

70

Helper utilities providing common functionality for startup and shutdown procedures.

71

72

```java { .api }

73

/**

74

* Utility class providing startup helper methods

75

*/

76

public class StartupHelperUtil {

77

78

/**

79

* Performs common startup initialization tasks

80

* @param servletContext the servlet context

81

*/

82

public static void initialize(ServletContext servletContext);

83

84

/**

85

* Sets up portal configuration during startup

86

*/

87

public static void setupConfiguration();

88

89

/**

90

* Initializes portal services during startup

91

*/

92

public static void initializeServices();

93

}

94

95

/**

96

* Utility class providing shutdown helper methods

97

*/

98

public class ShutdownHelperUtil {

99

100

/**

101

* Performs common shutdown cleanup tasks

102

* @param servletContext the servlet context

103

*/

104

public static void cleanup(ServletContext servletContext);

105

106

/**

107

* Shuts down portal services gracefully

108

*/

109

public static void shutdownServices();

110

111

/**

112

* Releases portal resources during shutdown

113

*/

114

public static void releaseResources();

115

}

116

```

117

118

### Authentication Events

119

120

Comprehensive authentication lifecycle management with pre and post processing hooks.

121

122

```java { .api }

123

/**

124

* Pre-login action executed before user authentication

125

*/

126

public class LoginPreAction extends Action {

127

128

/**

129

* Executes pre-login processing and validation

130

* @param request HTTP servlet request containing login credentials

131

* @param response HTTP servlet response

132

* @throws ActionException if pre-login processing fails

133

*/

134

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

135

}

136

137

/**

138

* Post-login action executed after successful user authentication

139

*/

140

public class LoginPostAction extends Action {

141

142

/**

143

* Executes post-login processing and setup

144

* @param request HTTP servlet request with authenticated user

145

* @param response HTTP servlet response

146

* @throws ActionException if post-login processing fails

147

*/

148

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

149

}

150

151

/**

152

* Pre-logout action executed before user logout

153

*/

154

public class LogoutPreAction extends Action {

155

156

/**

157

* Executes pre-logout processing and cleanup preparation

158

* @param request HTTP servlet request with user session

159

* @param response HTTP servlet response

160

* @throws ActionException if pre-logout processing fails

161

*/

162

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

163

}

164

165

/**

166

* Post-logout action executed after user logout

167

*/

168

public class LogoutPostAction extends Action {

169

170

/**

171

* Executes post-logout cleanup and finalization

172

* @param request HTTP servlet request after logout

173

* @param response HTTP servlet response

174

* @throws ActionException if post-logout processing fails

175

*/

176

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

177

}

178

179

/**

180

* Secure request action for security processing

181

*/

182

public class SecureRequestAction extends Action {

183

184

/**

185

* Processes security-related request handling

186

* @param request HTTP servlet request requiring security processing

187

* @param response HTTP servlet response

188

* @throws ActionException if security processing fails

189

*/

190

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

191

}

192

```

193

194

### Session Management Events

195

196

HTTP session lifecycle management with creation and destruction event handling.

197

198

```java { .api }

199

/**

200

* Session creation action executed when new HTTP sessions are created

201

*/

202

public class SessionCreateAction extends SessionAction {

203

204

/**

205

* Handles new session creation and initialization

206

* @param session the newly created HTTP session

207

* @throws ActionException if session creation processing fails

208

*/

209

public void run(HttpSession session) throws ActionException;

210

}

211

212

/**

213

* Session destruction action executed when HTTP sessions are destroyed

214

*/

215

public class SessionDestroyAction extends SessionAction {

216

217

/**

218

* Handles session destruction and cleanup

219

* @param session the HTTP session being destroyed

220

* @throws ActionException if session destruction processing fails

221

*/

222

public void run(HttpSession session) throws ActionException;

223

}

224

225

/**

226

* Session ID logging action for audit and debugging purposes

227

*/

228

public class LogSessionIdAction extends SessionAction {

229

230

/**

231

* Logs session ID information for auditing

232

* @param session the HTTP session to log

233

* @throws ActionException if logging fails

234

*/

235

public void run(HttpSession session) throws ActionException;

236

}

237

```

238

239

### Service Request Events

240

241

Service layer request processing with pre and post hooks for cross-cutting concerns.

242

243

```java { .api }

244

/**

245

* Pre-service action executed before service method calls

246

*/

247

public class ServicePreAction extends Action {

248

249

/**

250

* Executes pre-service processing such as validation and setup

251

* @param request HTTP servlet request for service call

252

* @param response HTTP servlet response

253

* @throws ActionException if pre-service processing fails

254

*/

255

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

256

}

257

258

/**

259

* Post-service action executed after service method calls

260

*/

261

public class ServicePostAction extends Action {

262

263

/**

264

* Executes post-service processing such as cleanup and logging

265

* @param request HTTP servlet request after service call

266

* @param response HTTP servlet response

267

* @throws ActionException if post-service processing fails

268

*/

269

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

270

}

271

272

/**

273

* Theme-specific pre-service action for theme processing

274

*/

275

public class ThemeServicePreAction extends Action {

276

277

/**

278

* Executes theme-specific pre-processing for service requests

279

* @param request HTTP servlet request with theme context

280

* @param response HTTP servlet response

281

* @throws ActionException if theme processing fails

282

*/

283

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

284

}

285

```

286

287

### Monitoring and Utility Events

288

289

System monitoring, resource management, and utility actions for portal maintenance.

290

291

```java { .api }

292

/**

293

* Memory usage logging action for system monitoring

294

*/

295

public class LogMemoryUsageAction extends Action {

296

297

/**

298

* Logs current memory usage statistics

299

* @param request HTTP servlet request

300

* @param response HTTP servlet response

301

* @throws ActionException if memory logging fails

302

*/

303

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

304

}

305

306

/**

307

* Thread count logging action for system monitoring

308

*/

309

public class LogThreadCountAction extends Action {

310

311

/**

312

* Logs current thread count and threading statistics

313

* @param request HTTP servlet request

314

* @param response HTTP servlet response

315

* @throws ActionException if thread logging fails

316

*/

317

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

318

}

319

320

/**

321

* Garbage collection action for memory management

322

*/

323

public class GarbageCollectorAction extends Action {

324

325

/**

326

* Triggers garbage collection and memory cleanup

327

* @param request HTTP servlet request

328

* @param response HTTP servlet response

329

* @throws ActionException if garbage collection fails

330

*/

331

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

332

}

333

334

/**

335

* Random layout assignment action for testing and development

336

*/

337

public class RandomLayoutAction extends Action {

338

339

/**

340

* Assigns random layouts for testing purposes

341

* @param request HTTP servlet request

342

* @param response HTTP servlet response

343

* @throws ActionException if layout assignment fails

344

*/

345

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

346

}

347

348

/**

349

* Random look and feel assignment action for UI testing

350

*/

351

public class RandomLookAndFeelAction extends Action {

352

353

/**

354

* Assigns random themes and look-and-feel for testing

355

* @param request HTTP servlet request

356

* @param response HTTP servlet response

357

* @throws ActionException if theme assignment fails

358

*/

359

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException;

360

}

361

```

362

363

## Usage Examples

364

365

**Portal Startup Configuration:**

366

367

```java

368

// Custom global startup action

369

public class CustomGlobalStartupAction extends GlobalStartupAction {

370

@Override

371

public void run(HttpServletRequest request, HttpServletResponse response)

372

throws ActionException {

373

374

// Initialize custom services

375

initializeCustomServices();

376

377

// Setup custom configuration

378

setupCustomConfiguration();

379

380

// Call parent startup logic

381

super.run(request, response);

382

}

383

384

private void initializeCustomServices() {

385

// Custom service initialization logic

386

}

387

388

private void setupCustomConfiguration() {

389

// Custom configuration setup

390

}

391

}

392

```

393

394

**Authentication Event Handling:**

395

396

```java

397

// Custom login processing

398

public class CustomLoginPreAction extends LoginPreAction {

399

@Override

400

public void run(HttpServletRequest request, HttpServletResponse response)

401

throws ActionException {

402

403

String username = request.getParameter("username");

404

String password = request.getParameter("password");

405

406

// Custom authentication validation

407

if (!validateCustomCriteria(username, password)) {

408

throw new ActionException("Custom validation failed");

409

}

410

411

// Additional security checks

412

performSecurityChecks(request);

413

414

// Call parent login logic

415

super.run(request, response);

416

}

417

}

418

419

// Custom post-login setup

420

public class CustomLoginPostAction extends LoginPostAction {

421

@Override

422

public void run(HttpServletRequest request, HttpServletResponse response)

423

throws ActionException {

424

425

// Setup user preferences

426

setupUserPreferences(request);

427

428

// Initialize user session data

429

initializeSessionData(request);

430

431

// Log login event

432

logLoginEvent(request);

433

434

super.run(request, response);

435

}

436

}

437

```

438

439

**Session Management:**

440

441

```java

442

// Custom session creation handling

443

public class CustomSessionCreateAction extends SessionCreateAction {

444

@Override

445

public void run(HttpSession session) throws ActionException {

446

447

// Initialize session attributes

448

session.setAttribute("createdTime", System.currentTimeMillis());

449

session.setAttribute("customData", new HashMap<>());

450

451

// Setup session tracking

452

setupSessionTracking(session);

453

454

super.run(session);

455

}

456

}

457

```

458

459

**Service Request Processing:**

460

461

```java

462

// Custom service pre-processing

463

public class CustomServicePreAction extends ServicePreAction {

464

@Override

465

public void run(HttpServletRequest request, HttpServletResponse response)

466

throws ActionException {

467

468

// Request validation

469

validateRequest(request);

470

471

// Security checks

472

performSecurityValidation(request);

473

474

// Setup request context

475

setupRequestContext(request);

476

477

super.run(request, response);

478

}

479

}

480

```

481

482

## Integration with Portal Framework

483

484

The lifecycle events system provides extensive integration points:

485

486

- **Extension Points** - Custom actions can be plugged in at any lifecycle stage

487

- **Cross-cutting Concerns** - Logging, security, monitoring can be applied consistently

488

- **Portal Services** - Events can trigger portal service operations

489

- **Plugin Integration** - Plugins can register custom lifecycle actions

490

- **Theme Integration** - Theme-specific processing during request lifecycle

491

- **Session Management** - Comprehensive session lifecycle control

492

493

## Event Configuration

494

495

Events are typically configured through portal properties or Spring configuration:

496

497

```properties

498

# Login events

499

login.events.pre=com.company.CustomLoginPreAction

500

login.events.post=com.company.CustomLoginPostAction

501

502

# Startup events

503

global.startup.events=com.company.CustomGlobalStartupAction

504

505

# Service events

506

servlet.service.events.pre=com.company.CustomServicePreAction

507

servlet.service.events.post=com.company.CustomServicePostAction

508

```

509

510

## Error Handling

511

512

Lifecycle events should handle errors gracefully:

513

514

- **ActionException** - Standard exception for action processing failures

515

- **Graceful Degradation** - Non-critical events should not block portal operation

516

- **Error Logging** - Comprehensive logging for debugging and monitoring

517

- **Rollback Procedures** - Cleanup procedures for failed operations

518

- **Event Chain Management** - Proper handling when event chains are interrupted

519

520

Best practices include implementing proper exception handling, comprehensive logging, and ensuring that critical system events (startup/shutdown) have appropriate fallback mechanisms.